diff --git a/.gitignore b/.gitignore
index 09cd281..965ea51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,15 @@
# gradle
.gradle/
+common/.gradle/
+fabric/.gradle/
+forge/.gradle/
+
build/
+common/build/
+fabric/build/
+forge/build/
+
out/
classes/
@@ -28,6 +36,7 @@ bin/
*.DS_Store
-# fabric
-
run/
+common/run/
+fabric/run/
+forge/run/
diff --git a/README.md b/README.md
index 122a0e8..10f0878 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,21 @@
![Automobility](./md/banner.png)
### A Minecraft mod adding customizable vehicles.
+**Automobility is currently in BETA!**
+The mod isn't feature-complete, and any feature requests would be greatly appreciated. Discuss features on the mod's GitHub Discussions page, or in the [Discord](https://discord.gg/7Aw3y4RtY9).
-## Available for Fabric/Quilt
+## Available for Fabric/Quilt and Forge
- Requires **[Fabric API](https://modrinth.com/mod/fabric-api)** (Fabric) or **[QSL](https://modrinth.com/mod/qsl)** (Quilt)
+- No additional mods required for Forge
-**Support for Forge or old versions is NOT PLANNED.**
+**Currently maintained for version 1.19.2, older versions are retired.**
## Getting Started
-- **Recipes:** Crafting recipes can be viewed using [**EMI**](https://www.curseforge.com/minecraft/mc-mods/emi).
+- **Recipes:** Crafting recipes can be viewed using [**EMI**](https://www.curseforge.com/minecraft/mc-mods/emi) (Fabric/Quilt) or [**JEI**](https://www.curseforge.com/minecraft/mc-mods/jei) (Forge).
- **Automobile Parts:** Craft an Auto Mechanic Table. Use the GUI to craft the frame, engine, and wheels for your automobile. You can optionally craft an attachment.
-- **Building your Automobile:** Craft an Automobile Assembler, as well as a Crowbar. Place parts on the assembler until the vehicle is complete. Use a crowbar to destroy the vehicle. After building, add your attachments.
+- **Building your Automobile:** Craft an Automobile Assembler, as well as a Crowbar. Place parts on the assembler until the vehicle is complete. Use a crowbar to destroy the vehicle.
+- **Enhancing your Automobile:** Use your Auto Mechanic Table to craft attachments, which can be placed on your Automobile to add exciting functionality or utility.
+- **Building:** You can use Slopes, Dash Panels, Off-Road tiles and more to build roads, racetracks, or obstacle courses.
![Automobile Construction](./md/construction.png)
![Automobile Types](./md/parking.png)
@@ -19,13 +24,13 @@
- W - Accelerate
- S - Brake/Reverse/Burnout
- A/D - Steer left/right
-- Space - Drift
+- Space - Drift/Deploy
-**Controller Support:** when using [MidnightControls](https://www.curseforge.com/minecraft/mc-mods/midnightcontrols), you will be able to control automobiles with the following default controls:
+**Controller Support (*Fabric and Quilt Exclusive*):** when using [MidnightControls](https://www.curseforge.com/minecraft/mc-mods/midnightcontrols), you will be able to control automobiles with the following default controls:
- A - Accelerate
- B - Brake/Reverse
- LStick - Steer left/right
-- RTrigger - Drift
+- RTrigger - Drift/Deploy
![Driving](./md/driving.png)
diff --git a/build.gradle b/build.gradle
index 5e1b84b..ab1c348 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,110 +1,30 @@
-plugins {
- id 'fabric-loom' version '0.11-SNAPSHOT'
- id 'maven-publish'
-}
-
-sourceCompatibility = JavaVersion.VERSION_17
-targetCompatibility = JavaVersion.VERSION_17
-
-archivesBaseName = project.archives_base_name
-version = project.mod_version
-group = project.maven_group
-
-repositories {
- maven { url = "https://maven.gegy.dev/" }
- maven { url = "https://maven.terraformersmc.com/" }
- maven { url = "https://aperlambda.github.io/maven" }
- // maven { url = "https://hephaestus.dev/release" }
- maven { url = "https://storage.googleapis.com/devan-maven/" }
- maven { url = "https://api.modrinth.com/maven" }
-
- maven { url = "https://jitpack.io" }
-}
-
-dependencies {
- // To change the versions see the gradle.properties file
- minecraft "com.mojang:minecraft:${project.minecraft_version}"
- mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
- modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
+subprojects {
+ apply plugin: 'java'
- // Fabric API. This is technically optional, but you probably want it anyway.
- modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
- // Controller Support
- modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}"
- modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
- modImplementation "maven.modrinth:midnightcontrols:${project.midnightcontrols_version}"
- api('org.aperlambda:lambdajcommon:1.8.1') {
- exclude group: 'com.google.code.gson'
- exclude group: 'com.google.guava'
- }
-
- // OBJ loader TODO: Update
- // modImplementation "dev.monarkhes:myron:${project.myron_version}"
- // include "dev.monarkhes:myron:${project.myron_version}"
-
- // Json't
- modImplementation "net.devtech:arrp:${project.arrp_version}"
- include "net.devtech:arrp:${project.arrp_version}"
-
- // Json entity models
- modImplementation "maven.modrinth:jsonem:${project.jsonem_version}"
- include "maven.modrinth:jsonem:${project.jsonem_version}"
-
- // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
- // You may need to force-disable transitiveness on them.
-}
+ archivesBaseName = project.archives_base_name
+ group = project.maven_group
-processResources {
- inputs.property "version", project.version
+ java.toolchain.languageVersion = JavaLanguageVersion.of(17)
+ java.withSourcesJar()
+ java.withJavadocJar()
- filesMatching("fabric.mod.json") {
- expand "version": project.version
+ jar {
+ from("LICENSE") {
+ rename { "${it}_${project.archivesBaseName}"}
+ }
}
-}
-
-tasks.withType(JavaCompile).configureEach {
- // ensure that the encoding is set to UTF-8, no matter what the system default is
- // this fixes some edge cases with special characters not displaying correctly
- // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
- // If Javadoc is generated, this must be specified in that task too.
- it.options.encoding = "UTF-8"
-
- it.options.release = 17
-}
-
-java {
- // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
- // if it is present.
- // If you remove this line, sources will not be generated.
- withSourcesJar()
-}
-jar {
- from("LICENSE") {
- rename { "${it}_${project.archivesBaseName}"}
- }
-}
+ repositories {
+ mavenCentral()
-// configure the maven publication
-publishing {
- publications {
- mavenJava(MavenPublication) {
- // add all the jars that should be included when publishing to maven
- artifact(remapJar) {
- builtBy remapJar
- }
- artifact(sourcesJar) {
- builtBy remapSourcesJar
- }
- }
+ maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
}
- // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
- repositories {
- // Add repositories to publish to here.
- // Notice: This block does NOT have the same function as the block in the top level.
- // The repositories here will be used for publishing your artifact, not for
- // retrieving dependencies.
+ tasks.withType(JavaCompile).configureEach {
+ it.options.encoding = "UTF-8"
+ it.options.release = 17
}
}
diff --git a/common/build.gradle b/common/build.gradle
new file mode 100644
index 0000000..de2c8d0
--- /dev/null
+++ b/common/build.gradle
@@ -0,0 +1,46 @@
+plugins {
+ id 'java'
+ id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT'
+ id 'maven-publish'
+}
+
+version = "${project.mod_version}+${project.minecraft_version}-common" as Object
+
+minecraft {
+ version(project.minecraft_version)
+ runs {
+ client('(Common) Client') {
+ workingDirectory(this.file("run"))
+ }
+ server('(Common) Server') {
+ workingDirectory(this.file("run"))
+ }
+ }
+}
+
+dependencies {
+ compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5'
+ implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
+}
+
+processResources {
+ def properties = project.properties.clone()
+
+ filesMatching('pack.mcmeta') {
+ expand properties as Map
+ }
+}
+
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ from components.java
+ groupId project.group
+ artifactId project.archivesBaseName
+ version project.version
+ }
+ }
+
+ repositories {
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/Automobility.java b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java
new file mode 100644
index 0000000..484b926
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/Automobility.java
@@ -0,0 +1,60 @@
+package io.github.foundationgames.automobility;
+
+import io.github.foundationgames.automobility.block.AutomobilityBlocks;
+import io.github.foundationgames.automobility.entity.AutomobilityEntities;
+import io.github.foundationgames.automobility.item.AutomobilityItems;
+import io.github.foundationgames.automobility.particle.AutomobilityParticles;
+import io.github.foundationgames.automobility.platform.Platform;
+import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipe;
+import io.github.foundationgames.automobility.recipe.AutoMechanicTableRecipeSerializer;
+import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler;
+import io.github.foundationgames.automobility.screen.SingleSlotScreenHandler;
+import io.github.foundationgames.automobility.sound.AutomobilitySounds;
+import io.github.foundationgames.automobility.util.AUtils;
+import io.github.foundationgames.automobility.util.Eventual;
+import io.github.foundationgames.automobility.util.InitlessConstants;
+import io.github.foundationgames.automobility.util.RegistryQueue;
+import io.github.foundationgames.automobility.util.network.CommonPackets;
+import net.minecraft.core.Registry;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.TagKey;
+import net.minecraft.world.inventory.MenuType;
+import net.minecraft.world.item.CreativeModeTab;
+import net.minecraft.world.level.block.Block;
+
+public class Automobility {
+ public static final String MOD_ID = InitlessConstants.AUTOMOBILITY;
+
+ public static final CreativeModeTab GROUP = Platform.get().creativeTab(rl("automobility"), AUtils::createGroupIcon);
+ public static final CreativeModeTab PREFABS = Platform.get().creativeTab(rl("automobility_prefabs"), AUtils::createPrefabsIcon);
+
+ public static final TagKey SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("slopes"));
+ public static final TagKey STEEP_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("steep_slopes"));
+ public static final TagKey NON_STEEP_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("non_steep_slopes"));
+ public static final TagKey STICKY_SLOPES = TagKey.create(Registry.BLOCK_REGISTRY, rl("sticky_slopes"));
+
+ public static final Eventual> AUTO_MECHANIC_SCREEN =
+ RegistryQueue.register(Registry.MENU, Automobility.rl("auto_mechanic_table"), () -> Platform.get().menuType(AutoMechanicTableScreenHandler::new));
+ public static final Eventual> SINGLE_SLOT_SCREEN =
+ RegistryQueue.register(Registry.MENU, Automobility.rl("single_slot"), () -> Platform.get().menuType(SingleSlotScreenHandler::new));
+
+ public static void init() {
+ AutomobilitySounds.init();
+ AutomobilityBlocks.init();
+ AutomobilityItems.init();
+ AutomobilityEntities.init();
+ AutomobilityParticles.init();
+ initOther();
+
+ CommonPackets.init();
+ }
+
+ public static void initOther() {
+ RegistryQueue.register(Registry.RECIPE_TYPE, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipe.TYPE);
+ RegistryQueue.register(Registry.RECIPE_SERIALIZER, AutoMechanicTableRecipe.ID, () -> AutoMechanicTableRecipeSerializer.INSTANCE);
+ }
+
+ public static ResourceLocation rl(String path) {
+ return new ResourceLocation(MOD_ID, path);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java b/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java
new file mode 100644
index 0000000..88b8c65
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/AutomobilityClient.java
@@ -0,0 +1,190 @@
+package io.github.foundationgames.automobility;
+
+import io.github.foundationgames.automobility.automobile.AutomobileComponent;
+import io.github.foundationgames.automobility.automobile.AutomobileData;
+import io.github.foundationgames.automobility.automobile.render.AutomobileModels;
+import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer;
+import io.github.foundationgames.automobility.automobile.render.ExhaustFumesModel;
+import io.github.foundationgames.automobility.automobile.render.SkidEffectModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel;
+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.DiamondEngineModel;
+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.engine.StoneEngineModel;
+import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel;
+import io.github.foundationgames.automobility.automobile.render.item.ItemRenderableAutomobile;
+import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel;
+import io.github.foundationgames.automobility.block.AutomobilityBlocks;
+import io.github.foundationgames.automobility.block.entity.render.AutomobileAssemblerBlockEntityRenderer;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.entity.AutomobilityEntities;
+import io.github.foundationgames.automobility.entity.render.AutomobileEntityRenderer;
+import io.github.foundationgames.automobility.item.AutomobileComponentItem;
+import io.github.foundationgames.automobility.item.AutomobilityItems;
+import io.github.foundationgames.automobility.platform.Platform;
+import io.github.foundationgames.automobility.screen.AutoMechanicTableScreen;
+import io.github.foundationgames.automobility.screen.SingleSlotScreen;
+import io.github.foundationgames.automobility.sound.AutomobileSoundInstance;
+import io.github.foundationgames.automobility.util.FloatFunc;
+import io.github.foundationgames.automobility.util.network.ClientPackets;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.color.block.BlockColor;
+import net.minecraft.client.color.item.ItemColor;
+import net.minecraft.client.model.Model;
+import net.minecraft.client.renderer.BiomeColors;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.GrassColor;
+
+import java.util.function.Function;
+
+public class AutomobilityClient {
+ public static final BlockColor GRASS_COLOR = (state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getAverageGrassColor(world, pos) : GrassColor.get(0.5D, 1.0D);
+ public static final ItemColor GRASS_ITEM_COLOR = (stack, tintIndex) -> GrassColor.get(0.5D, 1.0D);
+
+ public static void init() {
+ AutomobileModels.init();
+
+ initBlocks();
+ initItems();
+ initEntities();
+ ClientPackets.initClient();
+
+ Platform.get().registerMenuScreen(Automobility.AUTO_MECHANIC_SCREEN.require(), AutoMechanicTableScreen::new);
+ Platform.get().registerMenuScreen(Automobility.SINGLE_SLOT_SCREEN.require(), SingleSlotScreen::new);
+ }
+
+ public static void initBlocks() {
+ Platform.get().blockEntityRenderer(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY.require(), AutomobileAssemblerBlockEntityRenderer::new);
+ }
+
+ public static void initItems() {
+ var automobileReader = new AutomobileData();
+ var itemAutomobile = new ItemRenderableAutomobile(automobileReader);
+
+ Platform.get().builtinItemRenderer(AutomobilityItems.AUTOMOBILE.require(), (stack, type, pose, buffers, light, overlay) -> {
+ automobileReader.read(stack.getOrCreateTagElement("Automobile"));
+ float wheelDist = automobileReader.getFrame().model().lengthPx() / 16;
+ float scale = 1;
+ scale /= wheelDist * 0.77f;
+ pose.scale(scale, scale, scale);
+ AutomobileRenderer.render(pose, buffers, light, overlay, Minecraft.getInstance().getFrameTime(), itemAutomobile);
+ });
+ componentItemRenderer(AutomobilityItems.AUTOMOBILE_FRAME.require(),
+ t -> AutomobileModels.getModel(t.model().modelId()),
+ t -> t.model().texture(), t -> 1 / ((t.model().lengthPx() / 16) * 0.77f)
+ );
+ componentItemRenderer(AutomobilityItems.AUTOMOBILE_WHEEL.require(),
+ t -> AutomobileModels.getModel(t.model().modelId()),
+ t -> t.model().texture(), t -> 6 / t.model().radius()
+ );
+ componentItemRenderer(AutomobilityItems.AUTOMOBILE_ENGINE.require(),
+ t -> AutomobileModels.getModel(t.model().modelId()),
+ t -> t.model().texture(), t -> 1
+ );
+ componentItemRenderer(AutomobilityItems.REAR_ATTACHMENT.require(),
+ t -> AutomobileModels.getModel(t.model().modelId()),
+ t -> t.model().texture(), t -> 1
+ );
+ componentItemRenderer(AutomobilityItems.FRONT_ATTACHMENT.require(),
+ t -> AutomobileModels.getModel(t.model().modelId()),
+ t -> t.model().texture(), t -> t.model().scale()
+ );
+ }
+
+ public static > void componentItemRenderer(AutomobileComponentItem item, Function modelProvider, Function textureProvider, FloatFunc scaleProvider) {
+ Platform.get().builtinItemRenderer(item, (stack, mode, matrices, vertexConsumers, light, overlay) -> {
+ var component = item.getComponent(stack);
+ if (item.isVisible(component)) {
+ var model = modelProvider.apply(component);
+ float scale = scaleProvider.apply(component);
+ matrices.translate(0.5, 0, 0.5);
+ matrices.scale(scale, -scale, -scale);
+ model.renderToBuffer(matrices, vertexConsumers.getBuffer(model.renderType(textureProvider.apply(component))), light, overlay, 1, 1, 1, 1);
+ }
+ });
+ }
+
+ public static void initEntities() {
+ var libs = Platform.get();
+
+ libs.entityRenderer(AutomobilityEntities.AUTOMOBILE.require(), AutomobileEntityRenderer::new);
+
+ libs.modelLayer(StandardFrameModel.MODEL_LAYER);
+ libs.modelLayer(TractorFrameModel.MODEL_LAYER);
+ libs.modelLayer(MotorcarFrameModel.MODEL_LAYER);
+ libs.modelLayer(ShoppingCartFrameModel.MODEL_LAYER);
+ libs.modelLayer(CARRFrameModel.MODEL_LAYER);
+ libs.modelLayer(PineappleFrameModel.MODEL_LAYER);
+ libs.modelLayer(RickshawFrameModel.MODEL_LAYER);
+
+ libs.modelLayer(StandardWheelModel.MODEL_LAYER);
+ libs.modelLayer(OffRoadWheelModel.MODEL_LAYER);
+ libs.modelLayer(TractorWheelModel.MODEL_LAYER);
+ libs.modelLayer(CarriageWheelModel.MODEL_LAYER);
+ libs.modelLayer(SteelWheelModel.MODEL_LAYER);
+
+ libs.modelLayer(StoneEngineModel.MODEL_LAYER);
+ libs.modelLayer(IronEngineModel.MODEL_LAYER);
+ libs.modelLayer(CopperEngineModel.MODEL_LAYER);
+ libs.modelLayer(GoldEngineModel.MODEL_LAYER);
+ libs.modelLayer(DiamondEngineModel.MODEL_LAYER);
+ libs.modelLayer(CreativeEngineModel.MODEL_LAYER);
+
+ libs.modelLayer(PassengerSeatRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(BlockRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(GrindstoneRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(StonecutterRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(ChestRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(BannerPostRearAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(PlowRearAttachmentModel.MODEL_LAYER);
+
+ libs.modelLayer(MobControllerFrontAttachmentModel.MODEL_LAYER);
+ libs.modelLayer(HarvesterFrontAttachmentModel.MODEL_LAYER);
+
+ libs.modelLayer(SkidEffectModel.MODEL_LAYER);
+ libs.modelLayer(ExhaustFumesModel.MODEL_LAYER);
+
+ AutomobileEntity.engineSound = auto -> {
+ if (auto.getEngine().isEmpty()) {
+ return;
+ }
+
+ var client = Minecraft.getInstance();
+ client.getSoundManager().play(new AutomobileSoundInstance.EngineSound(client, auto));
+ };
+ AutomobileEntity.skidSound = auto -> {
+ var client = Minecraft.getInstance();
+ client.getSoundManager().play(new AutomobileSoundInstance.SkiddingSound(client, auto));
+ };
+ }
+
+ public static double modifyBoostFov(Minecraft client, double old, float tickDelta) {
+ var player = client.player;
+
+ if (player.getVehicle() instanceof AutomobileEntity auto) {
+ return old + ((Math.sqrt(auto.getBoostSpeed(tickDelta)) * 18) * client.options.fovEffectScale().get());
+ }
+
+ return old;
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileComponent.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java
index be60472..0b70868 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileData.java
@@ -1,7 +1,7 @@
package io.github.foundationgames.automobility.automobile;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.util.Identifier;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.resources.ResourceLocation;
public class AutomobileData {
private AutomobileFrame frame;
@@ -12,10 +12,10 @@ public class AutomobileData {
public AutomobileData() {
}
- public void read(NbtCompound nbt) {
- frame = AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("frame")));
- wheel = AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("wheels")));
- engine = AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("engine")));
+ public void read(CompoundTag nbt) {
+ frame = AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame")));
+ wheel = AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("wheels")));
+ engine = AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine")));
prefab = nbt.contains("isPrefab") && nbt.getBoolean("isPrefab");
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java
index 30f8c92..6d82614 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileEngine.java
@@ -1,52 +1,47 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.Automobility;
-import io.github.foundationgames.automobility.render.AutomobilityModels;
import io.github.foundationgames.automobility.sound.AutomobilitySounds;
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.sound.SoundEvent;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.util.Identifier;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
import java.util.function.Consumer;
-import java.util.function.Function;
+import java.util.function.Supplier;
public record AutomobileEngine(
- Identifier id,
+ ResourceLocation id,
float torque,
float speed,
- SoundEvent sound,
+ Supplier sound,
EngineModel model
) implements AutomobileComponent {
- public static final Identifier ID = Automobility.id("engine");
+ public static final ResourceLocation ID = Automobility.rl("engine");
public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>();
public static final AutomobileEngine EMPTY = REGISTRY.register(
- new AutomobileEngine(Automobility.id("empty"), 0.01f, 0.01f,
- SoundEvents.ENTITY_MINECART_INSIDE,
- new EngineModel(new Identifier("empty"), Automobility.id("empty"))
+ new AutomobileEngine(Automobility.rl("empty"), 0.01f, 0.01f,
+ () -> SoundEvents.MINECART_INSIDE,
+ new EngineModel(new ResourceLocation("empty"), Automobility.rl("empty"))
)
);
public static final AutomobileEngine STONE = REGISTRY.register(
- new AutomobileEngine(Automobility.id("stone"), 0.3f, 0.58f,
- AutomobilitySounds.STONE_ENGINE,
+ new AutomobileEngine(Automobility.rl("stone"), 0.3f, 0.58f,
+ AutomobilitySounds.STONE_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/stone.png"), Automobility.id("engine_stone"),
+ Automobility.rl("textures/entity/automobile/engine/stone.png"), Automobility.rl("engine_stone"),
new AutomobileEngine.ExhaustPos(0, 7f, -8.3f, 50, 0)
)
)
);
public static final AutomobileEngine IRON = REGISTRY.register(
- new AutomobileEngine(Automobility.id("iron"), 0.5f, 0.75f,
- AutomobilitySounds.IRON_ENGINE,
+ new AutomobileEngine(Automobility.rl("iron"), 0.5f, 0.75f,
+ AutomobilitySounds.IRON_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/iron.png"), Automobility.id("engine_iron"),
+ Automobility.rl("textures/entity/automobile/engine/iron.png"), Automobility.rl("engine_iron"),
new AutomobileEngine.ExhaustPos(-3.5f, 5.4f, -8, 26, 0),
new AutomobileEngine.ExhaustPos(3.5f, 5.4f, -8, 26, 0)
)
@@ -54,20 +49,20 @@ public record AutomobileEngine(
);
public static final AutomobileEngine COPPER = REGISTRY.register(
- new AutomobileEngine(Automobility.id("copper"), 0.375f, 0.68f,
- AutomobilitySounds.COPPER_ENGINE,
+ new AutomobileEngine(Automobility.rl("copper"), 0.375f, 0.68f,
+ AutomobilitySounds.COPPER_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/copper.png"), Automobility.id("engine_copper"),
+ Automobility.rl("textures/entity/automobile/engine/copper.png"), Automobility.rl("engine_copper"),
new AutomobileEngine.ExhaustPos(2, 1.625f, -8.95f, 26, 0)
)
)
);
public static final AutomobileEngine GOLD = REGISTRY.register(
- new AutomobileEngine(Automobility.id("gold"), 0.8f, 0.75f,
- AutomobilitySounds.GOLD_ENGINE,
+ new AutomobileEngine(Automobility.rl("gold"), 0.8f, 0.75f,
+ AutomobilitySounds.GOLD_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/gold.png"), Automobility.id("engine_gold"),
+ Automobility.rl("textures/entity/automobile/engine/gold.png"), Automobility.rl("engine_gold"),
new AutomobileEngine.ExhaustPos(4, 9.3f, -7.75f, 26, 0),
new AutomobileEngine.ExhaustPos(-4, 9.3f, -7.75f, 26, 0)
)
@@ -75,10 +70,10 @@ public record AutomobileEngine(
);
public static final AutomobileEngine DIAMOND = REGISTRY.register(
- new AutomobileEngine(Automobility.id("diamond"), 0.95f, 0.85f,
- AutomobilitySounds.DIAMOND_ENGINE,
+ new AutomobileEngine(Automobility.rl("diamond"), 0.95f, 0.85f,
+ AutomobilitySounds.DIAMOND_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/diamond.png"), Automobility.id("engine_diamond"),
+ Automobility.rl("textures/entity/automobile/engine/diamond.png"), Automobility.rl("engine_diamond"),
new AutomobileEngine.ExhaustPos(3, 3.8f, -7.6f, 40, 0),
new AutomobileEngine.ExhaustPos(-3, 3.8f, -7.6f, 40, 0),
new AutomobileEngine.ExhaustPos(4, 7.075f, -4.95f, 40, 0),
@@ -88,10 +83,10 @@ public record AutomobileEngine(
);
public static final AutomobileEngine CREATIVE = REGISTRY.register(
- new AutomobileEngine(Automobility.id("creative"), 1f, 1f,
- AutomobilitySounds.CREATIVE_ENGINE,
+ new AutomobileEngine(Automobility.rl("creative"), 1f, 1f,
+ AutomobilitySounds.CREATIVE_ENGINE::require,
new EngineModel(
- Automobility.id("textures/entity/automobile/engine/creative.png"), Automobility.id("engine_creative"),
+ Automobility.rl("textures/entity/automobile/engine/creative.png"), Automobility.rl("engine_creative"),
new AutomobileEngine.ExhaustPos(0, 7, -7, 90, 0)
)
)
@@ -106,7 +101,7 @@ public boolean isEmpty() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
@@ -117,7 +112,7 @@ public void forEachStat(Consumer> action) {
}
@Override
- public Identifier getId() {
+ public ResourceLocation getId() {
return this.id;
}
@@ -126,15 +121,10 @@ public String getTranslationKey() {
}
public static record EngineModel(
- Identifier texture,
- Identifier modelId,
+ ResourceLocation texture,
+ ResourceLocation modelId,
ExhaustPos ... exhausts
- ) {
- @Environment(EnvType.CLIENT)
- public Function model() {
- return AutomobilityModels.MODELS.get(modelId);
- }
- }
+ ) {}
public static record ExhaustPos(
float x, float y, float z,
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java
similarity index 80%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java
index 2dfaf8e..b9d60d6 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileFrame.java
@@ -1,32 +1,26 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.Automobility;
-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;
+import net.minecraft.resources.ResourceLocation;
import java.util.function.Consumer;
-import java.util.function.Function;
public record AutomobileFrame(
- Identifier id,
+ ResourceLocation id,
float weight,
FrameModel model
) implements AutomobileComponent {
- public static final Identifier ID = Automobility.id("frame");
+ public static final ResourceLocation ID = Automobility.rl("frame");
public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>();
public static final AutomobileFrame EMPTY = REGISTRY.register(
new AutomobileFrame(
- Automobility.id("empty"),
+ Automobility.rl("empty"),
0.25f,
new FrameModel(
- new Identifier("empty"),
- Automobility.id("empty"),
+ new ResourceLocation("empty"),
+ Automobility.rl("empty"),
WheelBase.basic(16, 16),
16, 8, 8, 4, 8, 8
)
@@ -68,11 +62,11 @@ public record AutomobileFrame(
public static final AutomobileFrame SHOPPING_CART = REGISTRY.register(
new AutomobileFrame(
- Automobility.id("shopping_cart"),
+ Automobility.rl("shopping_cart"),
0.25f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/shopping_cart.png"),
- Automobility.id("frame_shopping_cart"),
+ Automobility.rl("textures/entity/automobile/frame/shopping_cart.png"),
+ Automobility.rl("frame_shopping_cart"),
WheelBase.basic(17, 12.05f),
25,
11,
@@ -86,11 +80,11 @@ public record AutomobileFrame(
public static final AutomobileFrame C_ARR = REGISTRY.register(
new AutomobileFrame(
- Automobility.id("c_arr"),
+ Automobility.rl("c_arr"),
0.85f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/c_arr.png"),
- Automobility.id("frame_c_arr"),
+ Automobility.rl("textures/entity/automobile/frame/c_arr.png"),
+ Automobility.rl("frame_c_arr"),
WheelBase.basic(44.5f, 16),
44f,
6f,
@@ -104,11 +98,11 @@ public record AutomobileFrame(
public static final AutomobileFrame PINEAPPLE = REGISTRY.register(
new AutomobileFrame(
- Automobility.id("pineapple"),
+ Automobility.rl("pineapple"),
0.75f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/pineapple.png"),
- Automobility.id("frame_pineapple"),
+ Automobility.rl("textures/entity/automobile/frame/pineapple.png"),
+ Automobility.rl("frame_pineapple"),
WheelBase.basic(10, 18),
20,
16,
@@ -122,11 +116,11 @@ public record AutomobileFrame(
public static final AutomobileFrame DABABY = REGISTRY.register(
new AutomobileFrame(
- Automobility.id("dababy"),
+ Automobility.rl("dababy"),
0.93f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/c_arr.png"),
- Automobility.id("frame_dababy"),
+ Automobility.rl("textures/entity/automobile/frame/c_arr.png"),
+ Automobility.rl("frame_dababy"),
WheelBase.basic(40, 8),
40,
22,
@@ -140,11 +134,11 @@ public record AutomobileFrame(
private static AutomobileFrame standard(String color) {
return new AutomobileFrame(
- Automobility.id("standard_"+color),
+ Automobility.rl("standard_"+color),
0.6f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/standard_"+color+".png"),
- Automobility.id("frame_standard"),
+ Automobility.rl("textures/entity/automobile/frame/standard_"+color+".png"),
+ Automobility.rl("frame_standard"),
WheelBase.basic(26, 10),
26,
5,
@@ -158,11 +152,11 @@ private static AutomobileFrame standard(String color) {
private static AutomobileFrame motorcar(String variant, float weight) {
return new AutomobileFrame(
- Automobility.id(variant+"_motorcar"),
+ Automobility.rl(variant+"_motorcar"),
weight,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/"+variant+"_motorcar.png"),
- Automobility.id("frame_motorcar"),
+ Automobility.rl("textures/entity/automobile/frame/"+variant+"_motorcar.png"),
+ Automobility.rl("frame_motorcar"),
WheelBase.basic(32, 12),
28,
3,
@@ -176,11 +170,11 @@ private static AutomobileFrame motorcar(String variant, float weight) {
private static AutomobileFrame tractor(String color) {
return new AutomobileFrame(
- Automobility.id(color+"_tractor"),
+ Automobility.rl(color+"_tractor"),
0.9f,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/"+color+"_tractor.png"),
- Automobility.id("frame_tractor"),
+ Automobility.rl("textures/entity/automobile/frame/"+color+"_tractor.png"),
+ Automobility.rl("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),
@@ -199,11 +193,11 @@ private static AutomobileFrame tractor(String color) {
private static AutomobileFrame rickshaw(String prefix, float weight) {
return new AutomobileFrame(
- Automobility.id(prefix+"_rickshaw"),
+ Automobility.rl(prefix+"_rickshaw"),
weight,
new FrameModel(
- Automobility.id("textures/entity/automobile/frame/"+prefix+"_rickshaw.png"),
- Automobility.id("frame_rickshaw"),
+ Automobility.rl("textures/entity/automobile/frame/"+prefix+"_rickshaw.png"),
+ Automobility.rl("frame_rickshaw"),
new WheelBase(
new WheelBase.WheelPos(-11, -7.5f, 1, 0, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.LEFT),
new WheelBase.WheelPos(-11, 7.5f, 1, 180, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.RIGHT),
@@ -228,7 +222,7 @@ public boolean isEmpty() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
@@ -238,7 +232,7 @@ public void forEachStat(Consumer> action) {
}
@Override
- public Identifier getId() {
+ public ResourceLocation getId() {
return this.id;
}
@@ -247,8 +241,8 @@ public String getTranslationKey() {
}
public static record FrameModel(
- Identifier texture,
- Identifier modelId,
+ ResourceLocation texture,
+ ResourceLocation modelId,
WheelBase wheelBase,
float lengthPx,
float seatHeight,
@@ -256,10 +250,5 @@ public static record FrameModel(
float enginePosUp,
float rearAttachmentPos,
float frontAttachmentPos
- ) {
- @Environment(EnvType.CLIENT)
- public Function model() {
- return AutomobilityModels.MODELS.get(modelId);
- }
- }
+ ) {}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java
similarity index 58%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java
index 5e3d8ef..a3817f3 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobilePrefab.java
@@ -1,18 +1,18 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.item.AutomobilityItems;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.Identifier;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.ItemStack;
-public record AutomobilePrefab(Identifier id, AutomobileFrame frame, AutomobileWheel wheel, AutomobileEngine engine) {
+public record AutomobilePrefab(ResourceLocation id, AutomobileFrame frame, AutomobileWheel wheel, AutomobileEngine engine) {
public ItemStack toStack() {
- var stack = new ItemStack(AutomobilityItems.AUTOMOBILE);
- var automobile = stack.getOrCreateSubNbt("Automobile");
+ var stack = new ItemStack(AutomobilityItems.AUTOMOBILE.require());
+ var automobile = stack.getOrCreateTagElement("Automobile");
automobile.putString("frame", frame().getId().toString());
automobile.putString("wheels", wheel().getId().toString());
automobile.putString("engine", engine().getId().toString());
automobile.putBoolean("isPrefab", true);
- var display = stack.getOrCreateSubNbt("display");
+ var display = stack.getOrCreateTagElement("display");
display.putString("Name", String.format("{\"translate\":\"prefab.%s.%s\",\"italic\":\"false\"}", id().getNamespace(), id().getPath()));
return stack;
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java
similarity index 92%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java
index 9d46320..682741e 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileStats.java
@@ -1,12 +1,12 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.Automobility;
-import net.minecraft.util.Identifier;
+import net.minecraft.resources.ResourceLocation;
import java.util.function.Consumer;
public class AutomobileStats implements StatContainer {
- public static final Identifier ID = Automobility.id("automobile");
+ public static final ResourceLocation ID = Automobility.rl("automobile");
public static final DisplayStat STAT_ACCELERATION = new DisplayStat<>("acceleration", AutomobileStats::getAcceleration);
public static final DisplayStat STAT_COMFORTABLE_SPEED = new DisplayStat<>("comfortable_speed", stats -> stats.getComfortableSpeed() * 20);
public static final DisplayStat STAT_HANDLING = new DisplayStat<>("handling", AutomobileStats::getHandling);
@@ -44,7 +44,7 @@ public float getGrip() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java
similarity index 53%
rename from src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java
index 686ce3e..7ef1380 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/AutomobileWheel.java
@@ -1,45 +1,39 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.Automobility;
-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;
+import net.minecraft.resources.ResourceLocation;
import java.util.function.Consumer;
-import java.util.function.Function;
public record AutomobileWheel(
- Identifier id,
+ ResourceLocation id,
float size,
float grip,
WheelModel model,
Ability ... abilities
) implements AutomobileComponent {
- public static final Identifier ID = Automobility.id("wheel");
+ public static final ResourceLocation ID = Automobility.rl("wheel");
public static final SimpleMapContentRegistry REGISTRY = new SimpleMapContentRegistry<>();
public static final AutomobileWheel EMPTY = REGISTRY.register(
- new AutomobileWheel(Automobility.id("empty"), 0.01f, 0.01f, new WheelModel(1, 1, new Identifier("empty"), Automobility.id("empty")))
+ new AutomobileWheel(Automobility.rl("empty"), 0.01f, 0.01f, new WheelModel(1, 1, new ResourceLocation("empty"), Automobility.rl("empty")))
);
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"), Automobility.id("wheel_standard")))
+ new AutomobileWheel(Automobility.rl("standard"), 0.6f, 0.5f, new WheelModel(3, 3, Automobility.rl("textures/entity/automobile/wheel/standard.png"), Automobility.rl("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"), Automobility.id("wheel_off_road")))
+ new AutomobileWheel(Automobility.rl("off_road"), 1.1f, 0.8f, new WheelModel(8.4f, 5, Automobility.rl("textures/entity/automobile/wheel/off_road.png"), Automobility.rl("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"), Automobility.id("wheel_steel")))
+ new AutomobileWheel(Automobility.rl("steel"), 0.69f, 0.4f, new WheelModel(3.625f, 3, Automobility.rl("textures/entity/automobile/wheel/steel.png"), Automobility.rl("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"), Automobility.id("wheel_tractor")))
+ new AutomobileWheel(Automobility.rl("tractor"), 1.05f, 0.69f, new WheelModel(3.625f, 3, Automobility.rl("textures/entity/automobile/wheel/tractor.png"), Automobility.rl("wheel_tractor")))
);
public static final AutomobileWheel CARRIAGE = REGISTRY.register(carriage("carriage", 0.2f));
@@ -49,11 +43,11 @@ public record AutomobileWheel(
public static final AutomobileWheel BEJEWELED = REGISTRY.register(carriage("bejeweled", 0.475f));
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/c_arr.png"), Automobility.id("wheel_convertible")))
+ new AutomobileWheel(Automobility.rl("convertible"), 0.75f, 0.45f, new WheelModel(5.2f, 4.1f, Automobility.rl("textures/entity/automobile/frame/c_arr.png"), Automobility.rl("wheel_convertible")))
);
private static AutomobileWheel carriage(String name, float grip) {
- return new AutomobileWheel(Automobility.id(name), 1.05f, grip, new WheelModel(5, 2, Automobility.id("textures/entity/automobile/wheel/"+name+".png"), Automobility.id("wheel_carriage")));
+ return new AutomobileWheel(Automobility.rl(name), 1.05f, grip, new WheelModel(5, 2, Automobility.rl("textures/entity/automobile/wheel/"+name+".png"), Automobility.rl("wheel_carriage")));
}
public static final DisplayStat STAT_SIZE = new DisplayStat<>("size", AutomobileWheel::size);
@@ -65,7 +59,7 @@ public boolean isEmpty() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
@@ -76,7 +70,7 @@ public void forEachStat(Consumer> action) {
}
@Override
- public Identifier getId() {
+ public ResourceLocation getId() {
return this.id;
}
@@ -90,12 +84,7 @@ public enum Ability {
public static record WheelModel(
float radius,
float width,
- Identifier texture,
- Identifier modelId
- ) {
- @Environment(EnvType.CLIENT)
- public Function model() {
- return AutomobilityModels.MODELS.get(modelId);
- }
- }
+ ResourceLocation texture,
+ ResourceLocation modelId
+ ) {}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/BasicWheelBase.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java
similarity index 54%
rename from src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java
index fc63e58..91c5a7e 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/DisplayStat.java
@@ -1,22 +1,22 @@
package io.github.foundationgames.automobility.automobile;
import io.github.foundationgames.automobility.util.AUtils;
-import net.minecraft.text.Text;
-import net.minecraft.util.Formatting;
+import net.minecraft.ChatFormatting;
+import net.minecraft.network.chat.Component;
import java.util.List;
import java.util.function.ToDoubleFunction;
public record DisplayStat>(String name, ToDoubleFunction statProvider) {
- public static final Text STAT_SEPARATOR = Text.translatable("char.automobility.statSeparator");
+ public static final Component STAT_SEPARATOR = Component.translatable("char.automobility.statSeparator");
- public void appendTooltip(List tooltip, C container) {
+ public void appendTooltip(List tooltip, C container) {
var compKey = container.getContainerTextKey();
var statKey = "stat."+compKey+"."+this.name();
- tooltip.add(Text.translatable(statKey).formatted(Formatting.AQUA)
+ tooltip.add(Component.translatable(statKey).withStyle(ChatFormatting.AQUA)
.append(STAT_SEPARATOR)
- .append(Text.translatable(statKey+".readout",
+ .append(Component.translatable(statKey+".readout",
AUtils.DEC_TWO_PLACES.format(this.statProvider().applyAsDouble(container))
- ).formatted(Formatting.GREEN)));
+ ).withStyle(ChatFormatting.GREEN)));
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java
similarity index 69%
rename from src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java
index b8e9d4d..f0de21e 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/StatContainer.java
@@ -1,13 +1,13 @@
package io.github.foundationgames.automobility.automobile;
-import net.minecraft.text.Text;
-import net.minecraft.util.Identifier;
+import net.minecraft.network.chat.Component;
+import net.minecraft.resources.ResourceLocation;
import java.util.List;
import java.util.function.Consumer;
public interface StatContainer> {
- Identifier containerId();
+ ResourceLocation containerId();
default String getContainerTextKey() {
var id = this.containerId();
@@ -16,7 +16,7 @@ default String getContainerTextKey() {
void forEachStat(Consumer> action);
- default void appendTexts(List texts, C container) {
+ default void appendTexts(List texts, C container) {
this.forEachStat(stat -> stat.appendTooltip(texts, container));
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/WheelBase.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java
similarity index 67%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java
index 7e89b8b..fe9c091 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/BaseAttachment.java
@@ -3,11 +3,11 @@
import io.github.foundationgames.automobility.automobile.AutomobileComponent;
import io.github.foundationgames.automobility.block.AutomobilityBlocks;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.util.math.Vec3d;
-import net.minecraft.world.World;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.phys.Vec3;
public abstract class BaseAttachment> {
public final T type;
@@ -24,11 +24,11 @@ public final AutomobileEntity automobile() {
return this.automobile;
}
- protected final World world() {
- return this.automobile.world;
+ protected final Level world() {
+ return this.automobile.level;
}
- public abstract Vec3d pos();
+ public abstract Vec3 pos();
public float animation() {
return animation;
@@ -50,28 +50,28 @@ public void tick() {
public void onRemoved() {
}
- public abstract void writeNbt(NbtCompound nbt);
+ public abstract void writeNbt(CompoundTag nbt);
- public abstract void readNbt(NbtCompound nbt);
+ public abstract void readNbt(CompoundTag nbt);
- public void updatePacketRequested(ServerPlayerEntity player) {
+ public void updatePacketRequested(ServerPlayer player) {
}
protected boolean canModifyBlocks() {
- if (this.automobile.getFirstPassenger() instanceof PlayerEntity player && player.canModifyBlocks()) {
+ if (this.automobile.getFirstPassenger() instanceof Player player && player.mayBuild()) {
return true;
}
for (int i = 0; i < 4; i++) {
- if (world().getBlockState(this.automobile.getBlockPos().down(i)).isOf(AutomobilityBlocks.ALLOW)) {
+ if (world().getBlockState(this.automobile.blockPosition().below(i)).is(AutomobilityBlocks.ALLOW.require())) {
return true;
}
}
return false;
}
- public final NbtCompound toNbt() {
- var nbt = new NbtCompound();
+ public final CompoundTag toNbt() {
+ var nbt = new CompoundTag();
nbt.putString("type", this.type.getId().toString());
this.writeNbt(nbt);
return nbt;
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java
similarity index 61%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java
index e236c4e..b4047ce 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/FrontAttachmentType.java
@@ -9,41 +9,35 @@
import io.github.foundationgames.automobility.automobile.attachment.front.GrassCutterFrontAttachment;
import io.github.foundationgames.automobility.automobile.attachment.front.MobControllerFrontAttachment;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-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;
+import net.minecraft.resources.ResourceLocation;
import java.util.function.BiFunction;
import java.util.function.Consumer;
-import java.util.function.Function;
public record FrontAttachmentType(
- Identifier id, BiFunction, AutomobileEntity, T> constructor, FrontAttachmentModel model
+ ResourceLocation id, BiFunction, AutomobileEntity, T> constructor, FrontAttachmentModel model
) implements AutomobileComponent> {
- public static final Identifier ID = Automobility.id("front_attachment");
+ public static final ResourceLocation ID = Automobility.rl("front_attachment");
public static final SimpleMapContentRegistry> REGISTRY = new SimpleMapContentRegistry<>();
public static final FrontAttachmentType EMPTY = register(new FrontAttachmentType<>(
- Automobility.id("empty"), EmptyFrontAttachment::new, new FrontAttachmentModel(new Identifier("empty"), Automobility.id("empty"), 1)
+ Automobility.rl("empty"), EmptyFrontAttachment::new, new FrontAttachmentModel(new ResourceLocation("empty"), Automobility.rl("empty"), 1)
));
public static final FrontAttachmentType MOB_CONTROLLER = register(new FrontAttachmentType<>(
- Automobility.id("mob_controller"), MobControllerFrontAttachment::new,
- new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/mob_controller.png"), Automobility.id("frontatt_mob_controller"), 1.7f)
+ Automobility.rl("mob_controller"), MobControllerFrontAttachment::new,
+ new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/mob_controller.png"), Automobility.rl("frontatt_mob_controller"), 1.7f)
));
public static final FrontAttachmentType CROP_HARVESTER = register(new FrontAttachmentType<>(
- Automobility.id("crop_harvester"), CropHarvesterFrontAttachment::new,
- new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/crop_harvester.png"), Automobility.id("frontatt_harvester"), 0.83f)
+ Automobility.rl("crop_harvester"), CropHarvesterFrontAttachment::new,
+ new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/crop_harvester.png"), Automobility.rl("frontatt_harvester"), 0.83f)
));
public static final FrontAttachmentType GRASS_CUTTER = register(new FrontAttachmentType<>(
- Automobility.id("grass_cutter"), GrassCutterFrontAttachment::new,
- new FrontAttachmentModel(Automobility.id("textures/entity/automobile/front_attachment/grass_cutter.png"), Automobility.id("frontatt_harvester"), 0.83f)
+ Automobility.rl("grass_cutter"), GrassCutterFrontAttachment::new,
+ new FrontAttachmentModel(Automobility.rl("textures/entity/automobile/front_attachment/grass_cutter.png"), Automobility.rl("frontatt_harvester"), 0.83f)
));
@Override
@@ -52,7 +46,7 @@ public boolean isEmpty() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
@@ -61,7 +55,7 @@ public void forEachStat(Consumer>> action) {
}
@Override
- public Identifier getId() {
+ public ResourceLocation getId() {
return this.id();
}
@@ -70,10 +64,5 @@ private static FrontAttachmentType register(Front
return entry;
}
- public record FrontAttachmentModel(Identifier texture, Identifier modelId, float scale) {
- @Environment(EnvType.CLIENT)
- public Function model() {
- return AutomobilityModels.MODELS.get(modelId);
- }
- }
+ public record FrontAttachmentModel(ResourceLocation texture, ResourceLocation modelId, float scale) {}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java
similarity index 68%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java
index a9bf4fd..82fa32a 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.java
@@ -6,45 +6,39 @@
import io.github.foundationgames.automobility.automobile.attachment.rear.BackhoeRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment;
+import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.EmptyRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.PassengerSeatRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.PaverRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import io.github.foundationgames.automobility.automobile.attachment.rear.BlockRearAttachment;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-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;
+import net.minecraft.resources.ResourceLocation;
import java.util.function.BiFunction;
import java.util.function.Consumer;
-import java.util.function.Function;
public record RearAttachmentType(
- Identifier id, BiFunction, AutomobileEntity, T> constructor, RearAttachmentModel model
+ ResourceLocation id, BiFunction, AutomobileEntity, T> constructor, RearAttachmentModel model
) implements AutomobileComponent> {
- public static final Identifier ID = Automobility.id("rear_attachment");
+ public static final ResourceLocation ID = Automobility.rl("rear_attachment");
public static final SimpleMapContentRegistry> REGISTRY = new SimpleMapContentRegistry<>();
public static final RearAttachmentType EMPTY = register(new RearAttachmentType<>(
- Automobility.id("empty"), EmptyRearAttachment::new, new RearAttachmentModel(new Identifier("empty"), Automobility.id("empty"), 0)
+ Automobility.rl("empty"), EmptyRearAttachment::new, new RearAttachmentModel(new ResourceLocation("empty"), Automobility.rl("empty"), 0)
));
public static final RearAttachmentType PASSENGER_SEAT = register(new RearAttachmentType<>(
- Automobility.id("passenger_seat"), PassengerSeatRearAttachment::new,
- new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/passenger_seat.png"), Automobility.id("rearatt_passenger_seat"), 11)
+ Automobility.rl("passenger_seat"), PassengerSeatRearAttachment::new,
+ new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/passenger_seat.png"), Automobility.rl("rearatt_passenger_seat"), 11)
));
public static final RearAttachmentType CRAFTING_TABLE = register(block("crafting_table", BlockRearAttachment::craftingTable));
public static final RearAttachmentType LOOM = register(block("loom", BlockRearAttachment::loom));
public static final RearAttachmentType CARTOGRAPHY_TABLE = register(block("cartography_table", BlockRearAttachment::cartographyTable));
public static final RearAttachmentType SMITHING_TABLE = register(block("smithing_table", BlockRearAttachment::smithingTable));
- public static final RearAttachmentType GRINDSTONE = register(block("grindstone", Automobility.id("rearatt_grindstone"), BlockRearAttachment::grindstone));
- public static final RearAttachmentType STONECUTTER = register(block("stonecutter", Automobility.id("rearatt_stonecutter"), BlockRearAttachment::stonecutter));
+ public static final RearAttachmentType GRINDSTONE = register(block("grindstone", Automobility.rl("rearatt_grindstone"), BlockRearAttachment::grindstone));
+ public static final RearAttachmentType STONECUTTER = register(block("stonecutter", Automobility.rl("rearatt_stonecutter"), BlockRearAttachment::stonecutter));
public static final RearAttachmentType AUTO_MECHANIC_TABLE = register(block("auto_mechanic_table", BlockRearAttachment::autoMechanicTable));
public static final RearAttachmentType CHEST = register(chest("chest", BaseChestRearAttachment::chest));
@@ -52,18 +46,18 @@ public record RearAttachmentType(
public static final RearAttachmentType SADDLED_BARREL = register(block("saddled_barrel", BaseChestRearAttachment::saddledBarrel));
public static final RearAttachmentType BANNER_POST = register(new RearAttachmentType<>(
- Automobility.id("banner_post"), BannerPostRearAttachment::new,
- new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/banner_post.png"), Automobility.id("rearatt_banner_post"), 10)
+ Automobility.rl("banner_post"), BannerPostRearAttachment::new,
+ new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/banner_post.png"), Automobility.rl("rearatt_banner_post"), 10)
));
public static final RearAttachmentType BACKHOE = register(new RearAttachmentType<>(
- Automobility.id("backhoe"), BackhoeRearAttachment::new,
- new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/backhoe.png"), Automobility.id("rearatt_plow"), 11)
+ Automobility.rl("backhoe"), BackhoeRearAttachment::new,
+ new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/backhoe.png"), Automobility.rl("rearatt_plow"), 11)
));
public static final RearAttachmentType PAVER = register(new RearAttachmentType<>(
- Automobility.id("paver"), PaverRearAttachment::new,
- new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/paver.png"), Automobility.id("rearatt_plow"), 11)
+ Automobility.rl("paver"), PaverRearAttachment::new,
+ new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/paver.png"), Automobility.rl("rearatt_plow"), 11)
));
@Override
@@ -72,7 +66,7 @@ public boolean isEmpty() {
}
@Override
- public Identifier containerId() {
+ public ResourceLocation containerId() {
return ID;
}
@@ -81,22 +75,22 @@ public void forEachStat(Consumer>> action) {
}
@Override
- public Identifier getId() {
+ public ResourceLocation getId() {
return this.id;
}
private static RearAttachmentType chest(String name, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) {
- return block(name, Automobility.id("rearatt_chest"), constructor);
+ return block(name, Automobility.rl("rearatt_chest"), constructor);
}
private static RearAttachmentType block(String name, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) {
- return block(name, Automobility.id("rearatt_block"), constructor);
+ return block(name, Automobility.rl("rearatt_block"), constructor);
}
- private static RearAttachmentType block(String name, Identifier model, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) {
+ private static RearAttachmentType block(String name, ResourceLocation model, BiFunction, AutomobileEntity, BlockRearAttachment> constructor) {
return new RearAttachmentType<>(
- Automobility.id(name), constructor,
- new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/"+name+".png"), model, 11)
+ Automobility.rl(name), constructor,
+ new RearAttachmentModel(Automobility.rl("textures/entity/automobile/rear_attachment/"+name+".png"), model, 11)
);
}
@@ -105,10 +99,5 @@ private static RearAttachmentType register(RearAtt
return entry;
}
- public record RearAttachmentModel(Identifier texture, Identifier modelId, float pivotDistPx) {
- @Environment(EnvType.CLIENT)
- public Function model() {
- return AutomobilityModels.MODELS.get(modelId);
- }
- }
+ public record RearAttachmentModel(ResourceLocation texture, ResourceLocation modelId, float pivotDistPx) {}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java
similarity index 67%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java
index 0da92e2..fbb4843 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/BaseHarvesterFrontAttachment.java
@@ -2,19 +2,19 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.Block;
-import net.minecraft.block.BlockState;
-import net.minecraft.entity.Entity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.server.world.ServerWorld;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Vec3d;
+import net.minecraft.core.BlockPos;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.phys.Vec3;
import java.util.List;
public abstract class BaseHarvesterFrontAttachment extends FrontAttachment {
- private final BlockPos.Mutable blockIter = new BlockPos.Mutable();
- private Vec3d lastPos = null;
+ private final BlockPos.MutableBlockPos blockIter = new BlockPos.MutableBlockPos();
+ private Vec3 lastPos = null;
public BaseHarvesterFrontAttachment(FrontAttachmentType> type, AutomobileEntity automobile) {
super(type, automobile);
@@ -25,14 +25,14 @@ public void tick() {
super.tick();
var pos = this.pos();
- if (canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerWorld world) {
+ if (canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerLevel world) {
this.harvest(pos, world);
}
this.lastPos = pos;
}
- public void harvest(Vec3d pos, ServerWorld world) {
+ public void harvest(Vec3 pos, ServerLevel world) {
int minX = (int) Math.floor(pos.x - 0.5);
int maxX = (int) Math.floor(pos.x + 0.5);
int minZ = (int) Math.floor(pos.z - 0.5);
@@ -40,7 +40,7 @@ public void harvest(Vec3d pos, ServerWorld world) {
int y = (int) Math.floor(pos.y + 0.25);
Entity entity = this.automobile;
- if (this.automobile.hasPassengers()) {
+ if (this.automobile.isVehicle()) {
entity = this.automobile.getFirstPassenger();
}
@@ -49,8 +49,8 @@ public void harvest(Vec3d pos, ServerWorld world) {
blockIter.set(x, y, z);
var state = world.getBlockState(blockIter);
if (canHarvest(state)) {
- var stacks = Block.getDroppedStacks(state, world, blockIter, null, entity, ItemStack.EMPTY);
- world.breakBlock(blockIter, false);
+ var stacks = Block.getDrops(state, world, blockIter, null, entity, ItemStack.EMPTY);
+ world.destroyBlock(blockIter, false);
this.onBlockHarvested(state, blockIter, stacks);
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java
similarity index 70%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java
index 070d3b3..831fbd1 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/CropHarvesterFrontAttachment.java
@@ -2,11 +2,11 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.BlockState;
-import net.minecraft.block.CropBlock;
-import net.minecraft.item.BlockItem;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.math.BlockPos;
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.CropBlock;
+import net.minecraft.world.level.block.state.BlockState;
import java.util.List;
@@ -17,7 +17,7 @@ public CropHarvesterFrontAttachment(FrontAttachmentType> type, AutomobileEntit
@Override
public boolean canHarvest(BlockState state) {
- return state.getBlock() instanceof CropBlock crop && crop.isMature(state);
+ return state.getBlock() instanceof CropBlock crop && crop.isMaxAge(state);
}
@Override
@@ -27,10 +27,10 @@ public void onBlockHarvested(BlockState state, BlockPos pos, List dro
var world = world();
for (var drop : drops) {
if (!replanted && drop.getItem() instanceof BlockItem item) {
- var newState = item.getBlock().getDefaultState();
- if (newState.canPlaceAt(world, pos)) {
- world.setBlockState(pos, newState);
- drop.decrement(1);
+ var newState = item.getBlock().defaultBlockState();
+ if (newState.canSurvive(world, pos)) {
+ world.setBlockAndUpdate(pos, newState);
+ drop.shrink(1);
replanted = true;
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/EmptyFrontAttachment.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java
similarity index 56%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java
index 8befb3b..54a8255 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/FrontAttachment.java
@@ -4,14 +4,14 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.util.AUtils;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.ItemEntity;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.inventory.Inventory;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.math.Vec3d;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.Container;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.item.ItemEntity;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.phys.Vec3;
public abstract class FrontAttachment extends BaseAttachment> {
public FrontAttachment(FrontAttachmentType> type, AutomobileEntity automobile) {
@@ -19,7 +19,7 @@ public FrontAttachment(FrontAttachmentType> type, AutomobileEntity automobile)
}
@Override
- public Vec3d pos() {
+ public Vec3 pos() {
return this.automobile.getHeadPos();
}
@@ -29,31 +29,31 @@ protected void updateTrackedAnimation(float animation) {
}
public boolean canDrive(Entity entity) {
- return entity instanceof PlayerEntity;
+ return entity instanceof Player;
}
@Override
- public void writeNbt(NbtCompound nbt) {
+ public void writeNbt(CompoundTag nbt) {
}
@Override
- public void readNbt(NbtCompound nbt) {
+ public void readNbt(CompoundTag nbt) {
}
- public void dropOrTransfer(ItemStack stack, Vec3d dropPos) {
+ public void dropOrTransfer(ItemStack stack, Vec3 dropPos) {
var rearAtt = this.automobile.getRearAttachment();
boolean drop = true;
- if (rearAtt instanceof Inventory inv) {
+ if (rearAtt instanceof Container inv) {
if (AUtils.transferInto(stack, inv)) {
drop = false;
}
}
if (drop) {
- world().spawnEntity(new ItemEntity(world(), dropPos.x, dropPos.y, dropPos.z, stack));
+ world().addFreshEntity(new ItemEntity(world(), dropPos.x, dropPos.y, dropPos.z, stack));
}
}
- public static FrontAttachmentType> fromNbt(NbtCompound nbt) {
- return FrontAttachmentType.REGISTRY.get(Identifier.tryParse(nbt.getString("type")));
+ public static FrontAttachmentType> fromNbt(CompoundTag nbt) {
+ return FrontAttachmentType.REGISTRY.get(ResourceLocation.tryParse(nbt.getString("type")));
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java
similarity index 70%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java
index fdda9f2..ef86bcc 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/GrassCutterFrontAttachment.java
@@ -2,11 +2,11 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.BlockState;
-import net.minecraft.block.CropBlock;
-import net.minecraft.block.PlantBlock;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.math.BlockPos;
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.BushBlock;
+import net.minecraft.world.level.block.CropBlock;
+import net.minecraft.world.level.block.state.BlockState;
import java.util.List;
@@ -17,7 +17,7 @@ public GrassCutterFrontAttachment(FrontAttachmentType> type, AutomobileEntity
@Override
public boolean canHarvest(BlockState state) {
- return (state.getBlock() instanceof PlantBlock) && !(state.getBlock() instanceof CropBlock);
+ return (state.getBlock() instanceof BushBlock) && !(state.getBlock() instanceof CropBlock);
}
@Override
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java
similarity index 77%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java
index 6e6828f..8364415 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/front/MobControllerFrontAttachment.java
@@ -2,8 +2,8 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.mob.MobEntity;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.Mob;
public class MobControllerFrontAttachment extends FrontAttachment {
public MobControllerFrontAttachment(FrontAttachmentType> type, AutomobileEntity automobile) {
@@ -12,6 +12,6 @@ public MobControllerFrontAttachment(FrontAttachmentType> type, AutomobileEntit
@Override
public boolean canDrive(Entity entity) {
- return super.canDrive(entity) || (entity instanceof MobEntity);
+ return super.canDrive(entity) || (entity instanceof Mob);
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
similarity index 68%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
index 8402226..837ac18 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
@@ -2,13 +2,12 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.Block;
-import net.minecraft.block.BlockState;
-import net.minecraft.block.Blocks;
-import net.minecraft.sound.SoundEvent;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Direction;
+import net.minecraft.core.BlockPos;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.state.BlockState;
import java.util.List;
@@ -21,7 +20,7 @@ public BackhoeRearAttachment(RearAttachmentType> type, AutomobileEntity entity
@Override
public SoundEvent plowSound() {
- return SoundEvents.ITEM_HOE_TILL;
+ return SoundEvents.HOE_TILL;
}
@Override
@@ -31,10 +30,10 @@ public double searchHeight() {
@Override
public BlockState plowResult(BlockPos pos, BlockState state) {
- if (!this.world().getBlockState(pos.up()).isAir()) {
+ if (!this.world().getBlockState(pos.above()).isAir()) {
return state;
}
- return TILLABLE_BLOCKS.contains(state.getBlock()) ? Blocks.FARMLAND.getDefaultState() : state;
+ return TILLABLE_BLOCKS.contains(state.getBlock()) ? Blocks.FARMLAND.defaultBlockState() : state;
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java
similarity index 51%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java
index b51dc85..26f3235 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BannerPostRearAttachment.java
@@ -4,40 +4,40 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.screen.SingleSlotScreenHandler;
-import io.github.foundationgames.automobility.util.network.PayloadPackets;
-import net.minecraft.block.entity.BannerBlockEntity;
-import net.minecraft.block.entity.BannerPattern;
-import net.minecraft.inventory.Inventory;
-import net.minecraft.inventory.SimpleInventory;
-import net.minecraft.item.BannerItem;
-import net.minecraft.item.BlockItem;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.nbt.NbtList;
-import net.minecraft.screen.NamedScreenHandlerFactory;
-import net.minecraft.screen.ScreenHandlerContext;
-import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.text.Text;
-import net.minecraft.util.DyeColor;
-import net.minecraft.util.ItemScatterer;
-import net.minecraft.util.registry.RegistryEntry;
+import io.github.foundationgames.automobility.util.network.CommonPackets;
+import net.minecraft.core.Holder;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.network.chat.Component;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.Container;
+import net.minecraft.world.Containers;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.SimpleContainer;
+import net.minecraft.world.SimpleMenuProvider;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.item.BannerItem;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.DyeColor;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.entity.BannerBlockEntity;
+import net.minecraft.world.level.block.entity.BannerPattern;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class BannerPostRearAttachment extends RearAttachment {
- private static final Text UI_TITLE = Text.translatable("container.automobility.banner_post");
+ private static final Component UI_TITLE = Component.translatable("container.automobility.banner_post");
private @Nullable DyeColor baseColor = null;
- private NbtList patternNbt = new NbtList();
- private List, DyeColor>> patterns;
+ private ListTag patternNbt = new ListTag();
+ private List, DyeColor>> patterns;
- public final Inventory inventory = new SimpleInventory(1) {
+ public final Container inventory = new SimpleContainer(1) {
@Override
- public void setStack(int slot, ItemStack stack) {
- super.setStack(slot, stack);
+ public void setItem(int slot, ItemStack stack) {
+ super.setItem(slot, stack);
BannerPostRearAttachment.this.setFromItem(stack);
}
@@ -48,25 +48,25 @@ public BannerPostRearAttachment(RearAttachmentType> type, AutomobileEntity ent
}
public void sendPacket() {
- var nbt = new NbtCompound();
+ var nbt = new CompoundTag();
this.putToNbt(nbt);
- if (!this.world().isClient()) {
+ if (!this.world().isClientSide()) {
this.automobile().forNearbyPlayers(200, false, p ->
- PayloadPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, p));
+ CommonPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, p));
}
}
@Override
- public void updatePacketRequested(ServerPlayerEntity player) {
+ public void updatePacketRequested(ServerPlayer player) {
super.updatePacketRequested(player);
- var nbt = new NbtCompound();
+ var nbt = new CompoundTag();
this.putToNbt(nbt);
- PayloadPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, player);
+ CommonPackets.sendBannerPostAttachmentUpdatePacket(this.automobile(), nbt, player);
}
- public void putToNbt(NbtCompound nbt) {
+ public void putToNbt(CompoundTag nbt) {
if (this.baseColor != null) {
nbt.putInt("Color", this.baseColor.getId());
}
@@ -76,7 +76,7 @@ public void putToNbt(NbtCompound nbt) {
}
}
- public void setFromNbt(NbtCompound nbt) {
+ public void setFromNbt(CompoundTag nbt) {
if (nbt.contains("Color")) {
this.baseColor = DyeColor.byId(nbt.getInt("Color"));
} else {
@@ -86,7 +86,7 @@ public void setFromNbt(NbtCompound nbt) {
if (nbt.contains("Patterns", 9)) {
this.patternNbt = nbt.getList("Patterns", 10);
} else {
- this.patternNbt = new NbtList();
+ this.patternNbt = new ListTag();
}
this.patterns = null;
}
@@ -99,15 +99,15 @@ public void setFromItem(ItemStack stack) {
return;
}
- var nbt = BlockItem.getBlockEntityNbt(stack);
+ var nbt = BlockItem.getBlockEntityData(stack);
if (nbt != null && nbt.contains("Patterns", 9)) {
this.patternNbt = nbt.getList("Patterns", 10);
} else {
- this.patternNbt = new NbtList();
+ this.patternNbt = new ListTag();
}
this.patterns = null;
- if (!this.world().isClient()) {
+ if (!this.world().isClientSide()) {
this.sendPacket();
}
}
@@ -115,7 +115,7 @@ public void setFromItem(ItemStack stack) {
public void erase() {
this.baseColor = null;
- if (!this.world().isClient()) {
+ if (!this.world().isClientSide()) {
this.sendPacket();
}
}
@@ -124,9 +124,9 @@ public void erase() {
return this.baseColor;
}
- public List, DyeColor>> getPatterns() {
+ public List, DyeColor>> getPatterns() {
if (this.patterns == null) {
- this.patterns = BannerBlockEntity.getPatternsFromNbt(this.baseColor, this.patternNbt);
+ this.patterns = BannerBlockEntity.createPatterns(this.baseColor, this.patternNbt);
}
return this.patterns;
@@ -137,26 +137,26 @@ public void onRemoved() {
super.onRemoved();
var pos = this.pos();
- ItemScatterer.spawn(this.world(), pos.x, pos.y, pos.z, this.inventory.getStack(0));
+ Containers.dropItemStack(this.world(), pos.x, pos.y, pos.z, this.inventory.getItem(0));
}
@Override
- public void writeNbt(NbtCompound nbt) {
+ public void writeNbt(CompoundTag nbt) {
super.writeNbt(nbt);
this.putToNbt(nbt);
- var item = new NbtCompound();
- this.inventory.getStack(0).writeNbt(item);
+ var item = new CompoundTag();
+ this.inventory.getItem(0).save(item);
nbt.put("Banner", item);
}
@Override
- public void readNbt(NbtCompound nbt) {
+ public void readNbt(CompoundTag nbt) {
super.readNbt(nbt);
this.setFromNbt(nbt);
- this.inventory.setStack(0, ItemStack.fromNbt(nbt.getCompound("Banner")));
+ this.inventory.setItem(0, ItemStack.of(nbt.getCompound("Banner")));
}
@Override
@@ -165,8 +165,8 @@ public boolean hasMenu() {
}
@Override
- public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) {
- return new SimpleNamedScreenHandlerFactory((syncId, playerInv, player) ->
+ public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) {
+ return new SimpleMenuProvider((syncId, playerInv, player) ->
new SingleSlotScreenHandler(syncId, playerInv, this.inventory), UI_TITLE);
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java
new file mode 100644
index 0000000..77a0ecc
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.java
@@ -0,0 +1,126 @@
+package io.github.foundationgames.automobility.automobile.attachment.rear;
+
+import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.util.duck.EnderChestContainerDuck;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.chat.Component;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.SimpleMenuProvider;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.inventory.ChestMenu;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.entity.ChestLidController;
+import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
+import net.minecraft.world.level.block.state.BlockState;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.function.BiFunction;
+
+public class BaseChestRearAttachment extends BlockRearAttachment {
+ public static final Component TITLE_CHEST = Component.translatable("container.chest");
+ public static final Component TITLE_ENDER_CHEST = Component.translatable("container.enderchest");
+ public static final Component TITLE_BARREL = Component.translatable("container.barrel");
+
+ private final ContainerOpenersCounter viewerManager;
+ public final ChestLidController lidAnimator;
+
+ public BaseChestRearAttachment(RearAttachmentType> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) {
+ super(type, entity, block, screenProvider);
+ this.viewerManager = new ContainerOpenersCounter() {
+ protected void onOpen(Level world, BlockPos pos, BlockState state) {
+ sound(world, pos, BaseChestRearAttachment.this.getOpenSound());
+ }
+
+ protected void onClose(Level world, BlockPos pos, BlockState state) {
+ sound(world, pos, BaseChestRearAttachment.this.getCloseSound());
+ }
+
+ protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
+ if (!world.isClientSide()) {
+ BaseChestRearAttachment.this.updateTrackedAnimation(newViewerCount);
+ }
+ }
+
+ protected boolean isOwnContainer(Player player) {
+ if (!(player.containerMenu instanceof ChestMenu)) {
+ return false;
+ } else {
+ var inventory = ((ChestMenu)player.containerMenu).getContainer();
+ return inventory == BaseChestRearAttachment.this;
+ }
+ }
+ };
+ this.lidAnimator = new ChestLidController();
+ }
+
+ public void open(Player player) {
+ if (!player.isSpectator()) {
+ this.viewerManager.incrementOpeners(player, this.world(), this.automobile.blockPosition(), Blocks.AIR.defaultBlockState());
+ }
+ }
+
+ public void close(Player player) {
+ if (!player.isSpectator()) {
+ this.viewerManager.decrementOpeners(player, this.world(), this.automobile.blockPosition(), Blocks.AIR.defaultBlockState());
+ }
+ }
+
+ @Override
+ public void onTrackedAnimationUpdated(float animation) {
+ super.onTrackedAnimationUpdated(animation);
+
+ this.lidAnimator.shouldBeOpen(animation > 0);
+ }
+
+ @Override
+ public void tick() {
+ super.tick();
+
+ if (world().isClientSide()) {
+ this.lidAnimator.tickLid();
+ }
+ }
+
+ protected SoundEvent getOpenSound() {
+ return SoundEvents.ENDER_CHEST_OPEN;
+ }
+
+ protected SoundEvent getCloseSound() {
+ return SoundEvents.ENDER_CHEST_CLOSE;
+ }
+
+ private static void sound(Level world, BlockPos pos, SoundEvent soundEvent) {
+ world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundEvent, SoundSource.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
+ }
+
+ public static BaseChestRearAttachment chest(RearAttachmentType> type, AutomobileEntity entity) {
+ return new ChestRearAttachment(type, entity,
+ Blocks.ENDER_CHEST.defaultBlockState(),
+ (ctx, att) -> att instanceof ChestRearAttachment chest ? chest : null);
+ }
+
+ public static BaseChestRearAttachment enderChest(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BaseChestRearAttachment(type, entity,
+ Blocks.ENDER_CHEST.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) -> {
+ var enderChest = player.getEnderChestInventory();
+ if (att instanceof BaseChestRearAttachment chest) {
+ EnderChestContainerDuck.of(enderChest).automobility$setActiveAttachment(chest);
+ }
+ return ChestMenu.threeRows(syncId, inventory, enderChest);
+ }, TITLE_ENDER_CHEST)
+ );
+ }
+
+ public static BaseChestRearAttachment saddledBarrel(RearAttachmentType> type, AutomobileEntity entity) {
+ return new SaddledBarrelRearAttachment(type, entity,
+ Blocks.BARREL.defaultBlockState(),
+ (ctx, att) -> att instanceof SaddledBarrelRearAttachment barrel ? barrel : null);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
similarity index 70%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
index 9d0165b..fce36bd 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
@@ -2,18 +2,17 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.BlockState;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.server.world.ServerWorld;
-import net.minecraft.sound.SoundCategory;
-import net.minecraft.sound.SoundEvent;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Vec3d;
+import net.minecraft.core.BlockPos;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.phys.Vec3;
public abstract class BasePlowRearAttachment extends ExtendableRearAttachment {
- private final BlockPos.Mutable blockIter = new BlockPos.Mutable();
- private Vec3d lastPos = null;
+ private final BlockPos.MutableBlockPos blockIter = new BlockPos.MutableBlockPos();
+ private Vec3 lastPos = null;
public BasePlowRearAttachment(RearAttachmentType> type, AutomobileEntity entity) {
super(type, entity);
@@ -23,16 +22,16 @@ public BasePlowRearAttachment(RearAttachmentType> type, AutomobileEntity entit
@Override
public void tick() {
super.tick();
- var pos = this.origin().add(this.yawVec().multiply(0.11 * this.type.model().pivotDistPx()));
+ var pos = this.origin().add(this.yawVec().scale(0.11 * this.type.model().pivotDistPx()));
- if (this.extended() && canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerWorld world) {
+ if (this.extended() && canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerLevel world) {
this.plow(pos, world);
}
this.lastPos = pos;
}
- public void plow(Vec3d pos, ServerWorld world) {
+ public void plow(Vec3 pos, ServerLevel world) {
int minX = (int) Math.floor(pos.x - 0.5);
int maxX = (int) Math.floor(pos.x + 0.5);
int minZ = (int) Math.floor(pos.z - 0.5);
@@ -47,22 +46,22 @@ public void plow(Vec3d pos, ServerWorld world) {
var result = this.plowResult(blockIter, state);
if (result != state) {
- world.setBlockState(blockIter, result);
+ world.setBlockAndUpdate(blockIter, result);
playSound = true;
}
}
}
if (playSound) {
- world.playSound(null, pos.x, pos.y, pos.z, this.plowSound(), SoundCategory.BLOCKS, 0.8f, 1f);
+ world.playSound(null, pos.x, pos.y, pos.z, this.plowSound(), SoundSource.BLOCKS, 0.8f, 1f);
}
}
@Override
public void setExtended(boolean deployed) {
- if (!world().isClient() && deployed != this.extended()) {
+ if (!world().isClientSide() && deployed != this.extended()) {
var pos = this.pos();
- world().playSound(null, pos.x, pos.y, pos.z, SoundEvents.BLOCK_IRON_TRAPDOOR_CLOSE, SoundCategory.PLAYERS, 0.6f, 1.4f);
+ world().playSound(null, pos.x, pos.y, pos.z, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.PLAYERS, 0.6f, 1.4f);
}
super.setExtended(deployed);
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java
new file mode 100644
index 0000000..ba4b0da
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/BlockRearAttachment.java
@@ -0,0 +1,106 @@
+package io.github.foundationgames.automobility.automobile.attachment.rear;
+
+import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
+import io.github.foundationgames.automobility.block.AutoMechanicTableBlock;
+import io.github.foundationgames.automobility.block.AutomobilityBlocks;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.SimpleMenuProvider;
+import net.minecraft.world.inventory.CartographyTableMenu;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.inventory.CraftingMenu;
+import net.minecraft.world.inventory.GrindstoneMenu;
+import net.minecraft.world.inventory.LoomMenu;
+import net.minecraft.world.inventory.SmithingMenu;
+import net.minecraft.world.inventory.StonecutterMenu;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.state.BlockState;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.function.BiFunction;
+
+public class BlockRearAttachment extends RearAttachment {
+ public static final Component TITLE_CRAFTING = Component.translatable("container.crafting");
+ public static final Component TITLE_LOOM = Component.translatable("container.loom");
+ public static final Component TITLE_CARTOGRAPHY = Component.translatable("container.cartography_table");
+ public static final Component TITLE_SMITHING = Component.translatable("container.upgrade");
+ public static final Component TITLE_GRINDSTONE = Component.translatable("container.grindstone_title");
+ public static final Component TITLE_STONECUTTER = Component.translatable("container.stonecutter");
+
+ public final BlockState block;
+ private final @Nullable BiFunction screenProvider;
+
+ public BlockRearAttachment(RearAttachmentType> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) {
+ super(type, entity);
+ this.block = block;
+ this.screenProvider = screenProvider;
+ }
+
+ @Override
+ public boolean hasMenu() {
+ return this.screenProvider != null;
+ }
+
+ @Override
+ public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) {
+ return this.screenProvider != null ? this.screenProvider.apply(ctx, this) : null;
+ }
+
+ public static BlockRearAttachment craftingTable(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.CRAFTING_TABLE.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new CraftingMenu(syncId, inventory, ctx), TITLE_CRAFTING)
+ );
+ }
+
+ public static BlockRearAttachment loom(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.LOOM.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new LoomMenu(syncId, inventory, ctx), TITLE_LOOM)
+ );
+ }
+
+ public static BlockRearAttachment cartographyTable(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.CARTOGRAPHY_TABLE.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new CartographyTableMenu(syncId, inventory, ctx), TITLE_CARTOGRAPHY)
+ );
+ }
+
+ public static BlockRearAttachment smithingTable(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.SMITHING_TABLE.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new SmithingMenu(syncId, inventory, ctx), TITLE_SMITHING)
+ );
+ }
+
+ public static BlockRearAttachment grindstone(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.GRINDSTONE.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new GrindstoneMenu(syncId, inventory, ctx), TITLE_GRINDSTONE)
+ );
+ }
+
+ public static BlockRearAttachment stonecutter(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ Blocks.STONECUTTER.defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new StonecutterMenu(syncId, inventory, ctx), TITLE_STONECUTTER)
+ );
+ }
+
+ public static BlockRearAttachment autoMechanicTable(RearAttachmentType> type, AutomobileEntity entity) {
+ return new BlockRearAttachment(type, entity,
+ AutomobilityBlocks.AUTO_MECHANIC_TABLE.require().defaultBlockState(),
+ (ctx, att) -> new SimpleMenuProvider((syncId, inventory, player) ->
+ new AutoMechanicTableScreenHandler(syncId, inventory, ctx), AutoMechanicTableBlock.UI_TITLE)
+ );
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java
new file mode 100644
index 0000000..985a746
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.java
@@ -0,0 +1,130 @@
+package io.github.foundationgames.automobility.automobile.attachment.rear;
+
+import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import net.minecraft.core.NonNullList;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.chat.Component;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.world.Container;
+import net.minecraft.world.ContainerHelper;
+import net.minecraft.world.Containers;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.entity.player.Inventory;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.inventory.AbstractContainerMenu;
+import net.minecraft.world.inventory.ChestMenu;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.state.BlockState;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.function.BiFunction;
+
+public class ChestRearAttachment extends BaseChestRearAttachment implements Container, MenuProvider {
+ private NonNullList inventory;
+
+ public ChestRearAttachment(RearAttachmentType> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) {
+ super(type, entity, block, screenProvider);
+ this.inventory = NonNullList.withSize(27, ItemStack.EMPTY);
+ }
+
+ @Override
+ public void onRemoved() {
+ super.onRemoved();
+
+ var pos = this.pos();
+ this.inventory.forEach(s -> Containers.dropItemStack(this.world(), pos.x, pos.y, pos.z, s));
+ }
+
+ @Override
+ public int getContainerSize() {
+ return this.inventory.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.inventory.stream().allMatch(ItemStack::isEmpty);
+ }
+
+ @Override
+ public ItemStack getItem(int slot) {
+ return this.inventory.get(slot);
+ }
+
+ @Override
+ public ItemStack removeItem(int slot, int amount) {
+ return ContainerHelper.removeItem(this.inventory, slot, amount);
+ }
+
+ @Override
+ public ItemStack removeItemNoUpdate(int slot) {
+ return ContainerHelper.takeItem(this.inventory, slot);
+ }
+
+ @Override
+ public void setItem(int slot, ItemStack stack) {
+ this.inventory.set(slot, stack);
+ }
+
+ @Override
+ public void setChanged() {
+ this.automobile.markDirty();
+ }
+
+ @Override
+ public boolean stillValid(Player player) {
+ return true;
+ }
+
+ @Override
+ public Component getDisplayName() {
+ return BaseChestRearAttachment.TITLE_CHEST;
+ }
+
+ @Nullable
+ @Override
+ public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
+ return ChestMenu.threeRows(syncId, inv, this);
+ }
+
+ @Override
+ public void clearContent() {
+ this.inventory.clear();
+ }
+
+ @Override
+ public void startOpen(Player player) {
+ this.open(player);
+ }
+
+ @Override
+ public void stopOpen(Player player) {
+ this.close(player);
+ }
+
+ @Override
+ protected SoundEvent getOpenSound() {
+ return SoundEvents.CHEST_OPEN;
+ }
+
+ @Override
+ protected SoundEvent getCloseSound() {
+ return SoundEvents.CHEST_CLOSE;
+ }
+
+ @Override
+ public void writeNbt(CompoundTag nbt) {
+ super.writeNbt(nbt);
+
+ nbt.put("Items", ContainerHelper.saveAllItems(new CompoundTag(), this.inventory));
+ }
+
+ @Override
+ public void readNbt(CompoundTag nbt) {
+ super.readNbt(nbt);
+
+ ContainerHelper.loadAllItems(nbt.getCompound("Items"), this.inventory);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
similarity index 73%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
index e7de335..88d0a57 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
@@ -3,10 +3,10 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.util.AUtils;
-import io.github.foundationgames.automobility.util.network.PayloadPackets;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.util.math.MathHelper;
+import io.github.foundationgames.automobility.util.network.CommonPackets;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.util.Mth;
public abstract class ExtendableRearAttachment extends DeployableRearAttachment {
protected boolean extended;
@@ -19,11 +19,11 @@ protected ExtendableRearAttachment(RearAttachmentType> type, AutomobileEntity
}
public float extendAnimation(float delta) {
- return MathHelper.lerp(delta, lastExtendAnimation, extendAnimation) / 14;
+ return Mth.lerp(delta, lastExtendAnimation, extendAnimation) / 14;
}
public void setExtended(boolean extended) {
- if (!this.world().isClient()) {
+ if (!this.world().isClientSide()) {
this.updateTrackedAnimation(extended ? 1f : 0f);
}
@@ -38,28 +38,28 @@ public boolean extended() {
public void tick() {
super.tick();
- if (this.world().isClient()) {
+ if (this.world().isClientSide()) {
this.lastExtendAnimation = this.extendAnimation;
this.extendAnimation = AUtils.shift(this.extendAnimation, 1, this.extended() ? 0 : this.extendAnimTime());
}
}
@Override
- public void updatePacketRequested(ServerPlayerEntity player) {
+ public void updatePacketRequested(ServerPlayer player) {
super.updatePacketRequested(player);
- PayloadPackets.sendExtendableAttachmentUpdatePacket(this.automobile(), this.extended(), player);
+ CommonPackets.sendExtendableAttachmentUpdatePacket(this.automobile(), this.extended(), player);
}
@Override
- public void writeNbt(NbtCompound nbt) {
+ public void writeNbt(CompoundTag nbt) {
super.writeNbt(nbt);
nbt.putBoolean("extended", this.extended());
}
@Override
- public void readNbt(NbtCompound nbt) {
+ public void readNbt(CompoundTag nbt) {
super.readNbt(nbt);
this.setExtended(nbt.getBoolean("extended"));
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.java
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
similarity index 65%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
index 040d8ca..09fb589 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
@@ -3,11 +3,10 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.mixin.ShovelItemAccess;
-import net.minecraft.block.BlockState;
-import net.minecraft.sound.SoundEvent;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Direction;
+import net.minecraft.core.BlockPos;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.world.level.block.state.BlockState;
public class PaverRearAttachment extends BasePlowRearAttachment {
public PaverRearAttachment(RearAttachmentType> type, AutomobileEntity entity) {
@@ -16,7 +15,7 @@ public PaverRearAttachment(RearAttachmentType> type, AutomobileEntity entity)
@Override
public SoundEvent plowSound() {
- return SoundEvents.ITEM_SHOVEL_FLATTEN;
+ return SoundEvents.SHOVEL_FLATTEN;
}
@Override
@@ -26,10 +25,10 @@ public double searchHeight() {
@Override
public BlockState plowResult(BlockPos pos, BlockState state) {
- if (!this.world().getBlockState(pos.up()).isAir()) {
+ if (!this.world().getBlockState(pos.above()).isAir()) {
return state;
}
- return ShovelItemAccess.getPathStates().getOrDefault(state.getBlock(), state);
+ return ShovelItemAccess.getFlattenables().getOrDefault(state.getBlock(), state);
}
}
\ No newline at end of file
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java
similarity index 62%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java
index 0d7fb7a..d2a017c 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.java
@@ -3,12 +3,12 @@
import io.github.foundationgames.automobility.automobile.attachment.BaseAttachment;
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.screen.NamedScreenHandlerFactory;
-import net.minecraft.screen.ScreenHandlerContext;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.math.MathHelper;
-import net.minecraft.util.math.Vec3d;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.util.Mth;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
public abstract class RearAttachment extends BaseAttachment> {
@@ -22,20 +22,20 @@ protected RearAttachment(RearAttachmentType> type, AutomobileEntity entity) {
super(type, entity);
}
- public final Vec3d yawVec() {
- return new Vec3d(0, 0, 1).rotateY((float) Math.toRadians(180 - this.yaw()));
+ public final Vec3 yawVec() {
+ return new Vec3(0, 0, 1).yRot((float) Math.toRadians(180 - this.yaw()));
}
- public final Vec3d scaledYawVec() {
- return this.yawVec().multiply(this.type.model().pivotDistPx() * 0.0625);
+ public final Vec3 scaledYawVec() {
+ return this.yawVec().scale(this.type.model().pivotDistPx() * 0.0625);
}
- public final Vec3d origin() {
+ public final Vec3 origin() {
return this.automobile.getTailPos();
}
@Override
- public final Vec3d pos() {
+ public final Vec3 pos() {
return this.origin().add(this.scaledYawVec());
}
@@ -44,13 +44,13 @@ public float yaw() {
}
public float yaw(float delta) {
- return MathHelper.lerpAngleDegrees(delta, this.lastYaw, this.yaw());
+ return Mth.rotLerp(delta, this.lastYaw, this.yaw());
}
public void setYaw(float yaw) {
- float diff = MathHelper.wrapDegrees(yaw - this.automobile.getYaw());
- if (diff < -90 && diff > -180) yaw = this.automobile.getYaw() - 90;
- else if (diff > 90 && diff < 180) yaw = this.automobile.getYaw() + 90;
+ float diff = Mth.wrapDegrees(yaw - this.automobile.getYRot());
+ if (diff < -90 && diff > -180) yaw = this.automobile.getYRot() - 90;
+ else if (diff > 90 && diff < 180) yaw = this.automobile.getYRot() + 90;
this.yaw = yaw;
}
@@ -62,14 +62,14 @@ protected final void updateTrackedYaw(float yaw) {
public void onTrackedYawUpdated(float yaw) {
this.trackedYaw = yaw;
- this.yawLerpProgress = this.automobile.getType().getTrackTickInterval() + 1;
+ this.yawLerpProgress = this.automobile.getType().updateInterval() + 1;
}
protected final void updateTrackedAnimation(float animation) {
this.automobile.setTrackedRearAttachmentAnimation(animation);
}
- public final void pull(Vec3d movement) {
+ public final void pull(Vec3 movement) {
var vec = this.scaledYawVec().add(movement);
this.setYaw(180 - (float) Math.toDegrees(Math.atan2(vec.x, vec.z)));
}
@@ -81,11 +81,11 @@ public void tick() {
}
private void rotationTrackingTick() {
- if (!world().isClient()) {
+ if (!world().isClientSide()) {
this.yawLerpProgress = 0;
updateTrackedYaw(yaw());
} else if (yawLerpProgress > 0) {
- this.setYaw(this.yaw() + (MathHelper.wrapDegrees(this.trackedYaw - this.yaw()) / (float)this.yawLerpProgress));
+ this.setYaw(this.yaw() + (Mth.wrapDegrees(this.trackedYaw - this.yaw()) / (float)this.yawLerpProgress));
this.yawLerpProgress--;
}
@@ -103,19 +103,19 @@ public boolean hasMenu() {
return false;
}
- public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) {
+ public @Nullable MenuProvider createMenu(ContainerLevelAccess ctx) {
return null;
}
- public void writeNbt(NbtCompound nbt) {
+ public void writeNbt(CompoundTag nbt) {
nbt.putFloat("yaw", this.yaw());
}
- public void readNbt(NbtCompound nbt) {
+ public void readNbt(CompoundTag nbt) {
this.setYaw(nbt.getFloat("yaw"));
}
- public static RearAttachmentType> fromNbt(NbtCompound nbt) {
- return RearAttachmentType.REGISTRY.get(Identifier.tryParse(nbt.getString("type")));
+ public static RearAttachmentType> fromNbt(CompoundTag nbt) {
+ return RearAttachmentType.REGISTRY.get(ResourceLocation.tryParse(nbt.getString("type")));
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java
similarity index 66%
rename from src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java
index 22cdd46..5d3006c 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/attachment/rear/SaddledBarrelRearAttachment.java
@@ -2,33 +2,33 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.block.BlockState;
-import net.minecraft.screen.NamedScreenHandlerFactory;
-import net.minecraft.screen.ScreenHandlerContext;
-import net.minecraft.sound.SoundEvent;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction;
public class SaddledBarrelRearAttachment extends ChestRearAttachment {
- public SaddledBarrelRearAttachment(RearAttachmentType> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) {
+ public SaddledBarrelRearAttachment(RearAttachmentType> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction screenProvider) {
super(type, entity, block, screenProvider);
}
@Override
protected SoundEvent getOpenSound() {
- return SoundEvents.BLOCK_BARREL_OPEN;
+ return SoundEvents.BARREL_OPEN;
}
@Override
protected SoundEvent getCloseSound() {
- return SoundEvents.BLOCK_BARREL_CLOSE;
+ return SoundEvents.BARREL_CLOSE;
}
@Override
- public Text getDisplayName() {
+ public Component getDisplayName() {
return BaseChestRearAttachment.TITLE_BARREL;
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java
new file mode 100644
index 0000000..bd0e1d6
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileModels.java
@@ -0,0 +1,118 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.attachment.front.HarvesterFrontAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.front.MobControllerFrontAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.BannerPostRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.BlockRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.ChestRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.GrindstoneRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.PassengerSeatRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.PlowRearAttachmentModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.StonecutterRearAttachmentModel;
+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.DiamondEngineModel;
+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.engine.StoneEngineModel;
+import io.github.foundationgames.automobility.automobile.render.frame.CARRFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.DaBabyFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.MotorcarFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.PineappleFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.RickshawFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.ShoppingCartFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.StandardFrameModel;
+import io.github.foundationgames.automobility.automobile.render.frame.TractorFrameModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.CarriageWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.ConvertibleWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.OffRoadWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.StandardWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.SteelWheelModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.TractorWheelModel;
+import io.github.foundationgames.automobility.util.EntityRenderHelper;
+import net.minecraft.client.model.Model;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+public enum AutomobileModels {;
+ private static final ResourceLocation EMPTY = Automobility.rl("empty");
+
+ public static final ResourceLocation SKID_EFFECT = Automobility.rl("misc_skideffect");
+ public static final ResourceLocation EXHAUST_FUMES = Automobility.rl("misc_exhaustfumes");
+
+ private static final Map> modelProviders = new HashMap<>();
+ private static final Map models = new HashMap<>();
+
+ public static void register(ResourceLocation location, Function model) {
+ modelProviders.put(location, model);
+ }
+
+ public static void init() {
+ EntityRenderHelper.registerContextListener(ctx -> {
+ models.clear();
+ models.put(EMPTY, new EmptyModel());
+
+ for (var entry : modelProviders.entrySet()) {
+ models.put(entry.getKey(), entry.getValue().apply(ctx));
+ }
+ });
+
+ register(Automobility.rl("frame_standard"), StandardFrameModel::new);
+ register(Automobility.rl("frame_tractor"), TractorFrameModel::new);
+ register(Automobility.rl("frame_shopping_cart"), ShoppingCartFrameModel::new);
+ register(Automobility.rl("frame_c_arr"), CARRFrameModel::new);
+ register(Automobility.rl("frame_pineapple"), PineappleFrameModel::new);
+ register(Automobility.rl("frame_motorcar"), MotorcarFrameModel::new);
+ register(Automobility.rl("frame_rickshaw"), RickshawFrameModel::new);
+ register(Automobility.rl("frame_dababy"), DaBabyFrameModel::new);
+
+ register(Automobility.rl("wheel_standard"), StandardWheelModel::new);
+ register(Automobility.rl("wheel_off_road"), OffRoadWheelModel::new);
+ register(Automobility.rl("wheel_steel"), SteelWheelModel::new);
+ register(Automobility.rl("wheel_tractor"), TractorWheelModel::new);
+ register(Automobility.rl("wheel_carriage"), CarriageWheelModel::new);
+ register(Automobility.rl("wheel_convertible"), ConvertibleWheelModel::new);
+
+ register(Automobility.rl("engine_stone"), StoneEngineModel::new);
+ register(Automobility.rl("engine_iron"), IronEngineModel::new);
+ register(Automobility.rl("engine_copper"), CopperEngineModel::new);
+ register(Automobility.rl("engine_gold"), GoldEngineModel::new);
+ register(Automobility.rl("engine_diamond"), DiamondEngineModel::new);
+ register(Automobility.rl("engine_creative"), CreativeEngineModel::new);
+
+ register(Automobility.rl("rearatt_passenger_seat"), PassengerSeatRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_block"), BlockRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_grindstone"), GrindstoneRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_stonecutter"), StonecutterRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_chest"), ChestRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_banner_post"), BannerPostRearAttachmentModel::new);
+ register(Automobility.rl("rearatt_plow"), PlowRearAttachmentModel::new);
+
+ register(Automobility.rl("frontatt_mob_controller"), MobControllerFrontAttachmentModel::new);
+ register(Automobility.rl("frontatt_harvester"), HarvesterFrontAttachmentModel::new);
+
+ register(SKID_EFFECT, SkidEffectModel::new);
+ register(EXHAUST_FUMES, ExhaustFumesModel::new);
+ }
+
+ public static Model getModelOrNull(ResourceLocation location) {
+ return models.get(location);
+ }
+
+ public static Model getModel(ResourceLocation location) {
+ var result = getModelOrNull(location);
+ if (result == null) {
+ return getEmpty();
+ }
+ return result;
+ }
+
+ public static Model getEmpty() {
+ return getModelOrNull(EMPTY);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java
new file mode 100644
index 0000000..7ac8b3a
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/AutomobileRenderer.java
@@ -0,0 +1,208 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.automobile.AutomobileEngine;
+import io.github.foundationgames.automobility.automobile.WheelBase;
+import io.github.foundationgames.automobility.automobile.render.attachment.front.FrontAttachmentRenderModel;
+import io.github.foundationgames.automobility.automobile.render.attachment.rear.RearAttachmentRenderModel;
+import io.github.foundationgames.automobility.automobile.render.wheel.WheelContextReceiver;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.resources.ResourceLocation;
+
+public enum AutomobileRenderer {;
+ public static void render(
+ PoseStack pose, MultiBufferSource buffers, int light, int overlay,
+ float tickDelta, RenderableAutomobile automobile
+ ) {
+ var frame = automobile.getFrame();
+ var wheels = automobile.getWheels();
+ var engine = automobile.getEngine();
+
+ var skidEffectModel = AutomobileModels.getModel(AutomobileModels.SKID_EFFECT);
+ var exhaustFumesModel = AutomobileModels.getModel(AutomobileModels.EXHAUST_FUMES);
+
+ pose.pushPose();
+
+ pose.mulPose(Vector3f.ZP.rotationDegrees(180));
+ pose.mulPose(Vector3f.YP.rotationDegrees(automobile.getAutomobileYaw(tickDelta) + 180));
+
+ float chassisRaise = wheels.model().radius() / 16;
+ float bounce = automobile.getSuspensionBounce(tickDelta) * 0.048f;
+
+ var frameModel = AutomobileModels.getModel(automobile.getFrame().model().modelId());
+ var wheelModel = AutomobileModels.getModel(automobile.getWheels().model().modelId());
+ var engineModel = AutomobileModels.getModel(automobile.getEngine().model().modelId());
+ var rearAttachmentModel = AutomobileModels.getModel(automobile.getRearAttachmentType().model().modelId());
+ var frontAttachmentModel = AutomobileModels.getModel(automobile.getFrontAttachmentType().model().modelId());
+
+ pose.translate(0, -chassisRaise, 0);
+
+ // Frame, engine, exhaust
+ pose.pushPose();
+
+ pose.translate(0, bounce + (automobile.engineRunning() ? (Math.cos((automobile.getTime() + tickDelta) * 2.7) / 156) : 0), 0);
+ var frameTexture = frame.model().texture();
+ var engineTexture = engine.model().texture();
+ if (!frame.isEmpty() && frameModel != null) {
+ frameModel.renderToBuffer(pose, buffers.getBuffer(frameModel.renderType(frameTexture)), light, overlay, 1, 1, 1, 1);
+ if (frameModel instanceof BaseModel base) {
+ base.doOtherLayerRender(pose, buffers, light, overlay);
+ }
+ }
+
+ float eBack = frame.model().enginePosBack() / 16;
+ float eUp = frame.model().enginePosUp() / 16;
+ pose.translate(0, -eUp, eBack);
+ pose.mulPose(Vector3f.YP.rotationDegrees(180));
+ if (!engine.isEmpty() && engineModel != null) {
+ engineModel.renderToBuffer(pose, buffers.getBuffer(engineModel.renderType(engineTexture)), light, overlay, 1, 1, 1, 1);
+ if (engineModel instanceof BaseModel base) {
+ base.doOtherLayerRender(pose, buffers, light, overlay);
+ }
+ }
+
+ VertexConsumer exhaustBuffer = null;
+ ResourceLocation[] exhaustTexes;
+ if (automobile.getBoostTimer() > 0) {
+ exhaustTexes = ExhaustFumesModel.FLAME_TEXTURES;
+ int index = (int)(automobile.getTime() % exhaustTexes.length);
+ exhaustBuffer = buffers.getBuffer(RenderType.eyes(exhaustTexes[index]));
+ } else if (automobile.engineRunning()) {
+ exhaustTexes = ExhaustFumesModel.SMOKE_TEXTURES;
+ int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % exhaustTexes.length);
+ exhaustBuffer = buffers.getBuffer(RenderType.entityTranslucent(exhaustTexes[index]));
+ }
+ if (exhaustBuffer != null) {
+ for (AutomobileEngine.ExhaustPos exhaust : engine.model().exhausts()) {
+ pose.pushPose();
+
+ pose.translate(exhaust.x() / 16, -exhaust.y() / 16, exhaust.z() / 16);
+ pose.mulPose(Vector3f.YP.rotationDegrees(exhaust.yaw()));
+ pose.mulPose(Vector3f.XP.rotationDegrees(exhaust.pitch()));
+ exhaustFumesModel.renderToBuffer(pose, exhaustBuffer, light, overlay, 1, 1, 1, 1);
+
+ pose.popPose();
+ }
+ }
+ pose.popPose();
+
+ // Rear Attachment
+ var rearAtt = automobile.getRearAttachmentType();
+ if (!rearAtt.isEmpty()) {
+ pose.pushPose();
+ pose.translate(0, chassisRaise, frame.model().rearAttachmentPos() / 16);
+ pose.mulPose(Vector3f.YN.rotationDegrees(automobile.getAutomobileYaw(tickDelta) - automobile.getRearAttachmentYaw(tickDelta)));
+
+ pose.translate(0, 0, rearAtt.model().pivotDistPx() / 16);
+ if (rearAttachmentModel instanceof RearAttachmentRenderModel rm) {
+ rm.setRenderState(automobile.getRearAttachment(), (float) Math.toRadians(automobile.getWheelAngle(tickDelta)), tickDelta);
+ }
+ rearAttachmentModel.renderToBuffer(pose, buffers.getBuffer(rearAttachmentModel.renderType(rearAtt.model().texture())), light, overlay, 1, 1, 1, 1);
+ if (rearAttachmentModel instanceof BaseModel base) {
+ base.doOtherLayerRender(pose, buffers, light, overlay);
+ }
+ pose.popPose();
+ }
+
+ // Front Attachment
+ var frontAtt = automobile.getFrontAttachmentType();
+ if (!frontAtt.isEmpty()) {
+ pose.pushPose();
+ pose.translate(0, 0, frame.model().frontAttachmentPos() / -16);
+
+ if (frontAttachmentModel instanceof FrontAttachmentRenderModel fm) {
+ fm.setRenderState(automobile.getFrontAttachment(), chassisRaise, tickDelta);
+ }
+ frontAttachmentModel.renderToBuffer(pose, buffers.getBuffer(frontAttachmentModel.renderType(frontAtt.model().texture())), light, overlay, 1, 1, 1, 1);
+ if (frontAttachmentModel instanceof BaseModel base) {
+ base.doOtherLayerRender(pose, buffers, light, overlay);
+ }
+ pose.popPose();
+ }
+
+ // WHEELS ----------------------------------------
+ var wPoses = frame.model().wheelBase().wheels;
+
+ if (!wheels.isEmpty()) {
+ var wheelBuffer = buffers.getBuffer(wheelModel.renderType(wheels.model().texture()));
+ float wheelAngle = automobile.getWheelAngle(tickDelta);
+ int wheelCount = automobile.getWheelCount();
+
+ for (var pos : wPoses) {
+ if (wheelCount <= 0) {
+ break;
+ }
+
+ if (wheelModel instanceof WheelContextReceiver receiver) {
+ receiver.provideContext(pos);
+ }
+ float scale = pos.scale();
+ float wheelRadius = wheels.model().radius() - (wheels.model().radius() * (scale - 1));
+ pose.pushPose();
+
+ pose.translate(pos.right() / 16, wheelRadius / 16, -pos.forward() / 16);
+
+ if (pos.end() == WheelBase.WheelEnd.FRONT) pose.mulPose(Vector3f.YP.rotationDegrees(automobile.getSteering(tickDelta) * 27));
+ pose.translate(0, -chassisRaise, 0);
+ pose.mulPose(Vector3f.XP.rotationDegrees(wheelAngle));
+ pose.scale(scale, scale, scale);
+
+ pose.mulPose(Vector3f.YP.rotationDegrees(180 + pos.yaw()));
+
+ wheelModel.renderToBuffer(pose, wheelBuffer, light, overlay, 1, 1, 1, 1);
+ if (wheelModel instanceof BaseModel base) {
+ base.doOtherLayerRender(pose, buffers, light, overlay);
+ }
+
+ pose.popPose();
+
+ wheelCount--;
+ }
+ }
+
+ // Skid effects
+ if ((automobile.getTurboCharge() > AutomobileEntity.SMALL_TURBO_TIME || automobile.debris()) && automobile.automobileOnGround()) {
+ var skidTexes = SkidEffectModel.COOL_SPARK_TEXTURES;
+ boolean bright = true;
+ float r = 1;
+ float g = 1;
+ float b = 1;
+ if (automobile.getTurboCharge() > AutomobileEntity.LARGE_TURBO_TIME) {
+ skidTexes = SkidEffectModel.FLAME_TEXTURES;
+ } else if (automobile.getTurboCharge() > AutomobileEntity.MEDIUM_TURBO_TIME) {
+ skidTexes = SkidEffectModel.HOT_SPARK_TEXTURES;
+ } else if (automobile.debris()) {
+ skidTexes = SkidEffectModel.DEBRIS_TEXTURES;
+ var c = automobile.debrisColor();
+ r = c.x() * 0.85f;
+ g = c.y() * 0.85f;
+ b = c.z() * 0.85f;
+ bright = false;
+ }
+ int index = (int)Math.floor(((automobile.getTime() + tickDelta) / 1.5f) % skidTexes.length);
+ var skidEffectBuffer = buffers.getBuffer(bright ? RenderType.eyes(skidTexes[index]) : RenderType.entitySmoothCutout(skidTexes[index]));
+
+ for (var pos : wPoses) {
+ if (pos.end() == WheelBase.WheelEnd.BACK) {
+ float scale = pos.scale();
+ float heightOffset = wheels.model().radius();
+ float wheelRadius = wheels.model().radius() * scale;
+ float wheelWidth = (wheels.model().width() / 16) * scale;
+ float back = (wheelRadius > 2) ? (float) (Math.sqrt((wheelRadius * wheelRadius) - Math.pow(wheelRadius - 2, 2)) - 0.85) / 16 : 0.08f;
+ pose.pushPose();
+ pose.translate((pos.right() / 16) + (wheelWidth * (pos.side() == WheelBase.WheelSide.RIGHT ? 1 : -1)), heightOffset / 16, (-pos.forward() / 16) + back);
+ pose.scale(pos.side() == WheelBase.WheelSide.LEFT ? -1 : 1, 1, -1);
+ skidEffectModel.renderToBuffer(pose, skidEffectBuffer, light, overlay, r, g, b, 0.6f);
+ pose.popPose();
+ }
+ }
+ }
+ // -----------------------------------------------
+
+ pose.popPose();
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java
new file mode 100644
index 0000000..450fcb8
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/BaseModel.java
@@ -0,0 +1,47 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.model.Model;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
+
+import java.util.function.Function;
+
+public class BaseModel extends Model {
+ protected final ModelPart root;
+
+ public BaseModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) {
+ super(layerFactory);
+ this.root = ctx.bakeLayer(layer).getChild("main");
+ }
+
+ protected void prepare(PoseStack matrices) {
+ }
+
+ @Override
+ public final void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ matrices.pushPose();
+ this.prepare(matrices);
+ this.root.render(matrices, vertices, light, overlay, red, green, blue, alpha);
+ renderExtra(matrices, vertices, light, overlay, red, green, blue, alpha);
+ matrices.popPose();
+ }
+
+ public final void doOtherLayerRender(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) {
+ matrices.pushPose();
+ this.prepare(matrices);
+ this.renderOtherLayer(matrices, consumers, light, overlay);
+ matrices.popPose();
+ }
+
+ public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ }
+
+ public void renderOtherLayer(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) {
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java
new file mode 100644
index 0000000..eba60af
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/EmptyModel.java
@@ -0,0 +1,16 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.model.Model;
+import net.minecraft.client.renderer.RenderType;
+
+public class EmptyModel extends Model {
+ public EmptyModel() {
+ super(RenderType::entitySolid);
+ }
+
+ @Override
+ public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java
new file mode 100644
index 0000000..0df2b51
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/ExhaustFumesModel.java
@@ -0,0 +1,28 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
+
+public class ExhaustFumesModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile_exhaust_fumes"), "main");
+
+ public static final ResourceLocation[] SMOKE_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_0.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_1.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_2.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_smoke_3.png")
+ };
+ public static final ResourceLocation[] FLAME_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_0.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_1.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_2.png"),
+ Automobility.rl("textures/entity/automobile/exhaust/exhaust_flames_3.png")
+ };
+
+ public ExhaustFumesModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java
similarity index 79%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java
index 90787f1..541f109 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.java
@@ -1,5 +1,6 @@
package io.github.foundationgames.automobility.automobile.render;
+import com.mojang.math.Vector3f;
import io.github.foundationgames.automobility.automobile.AutomobileEngine;
import io.github.foundationgames.automobility.automobile.AutomobileFrame;
import io.github.foundationgames.automobility.automobile.AutomobileWheel;
@@ -7,9 +8,6 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.client.model.Model;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.util.math.Vec3f;
import org.jetbrains.annotations.Nullable;
public interface RenderableAutomobile {
@@ -37,16 +35,6 @@ default FrontAttachmentType> getFrontAttachmentType() {
return this.getFrontAttachment().type;
}
- Model getFrameModel(EntityRendererFactory.Context ctx);
-
- Model getWheelModel(EntityRendererFactory.Context ctx);
-
- Model getEngineModel(EntityRendererFactory.Context ctx);
-
- Model getRearAttachmentModel(EntityRendererFactory.Context ctx);
-
- Model getFrontAttachmentModel(EntityRendererFactory.Context ctx);
-
float getAutomobileYaw(float tickDelta);
float getRearAttachmentYaw(float tickDelta);
@@ -73,5 +61,5 @@ default int getWheelCount() {
boolean debris();
- Vec3f debrisColor();
+ Vector3f debrisColor();
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java
new file mode 100644
index 0000000..73a99b9
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/SkidEffectModel.java
@@ -0,0 +1,36 @@
+package io.github.foundationgames.automobility.automobile.render;
+
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
+
+public class SkidEffectModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile_skid_effect"), "main");
+
+ public static final ResourceLocation[] COOL_SPARK_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_0.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_1.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_cool_sparks_2.png")
+ };
+ public static final ResourceLocation[] HOT_SPARK_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_0.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_1.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_hot_sparks_2.png")
+ };
+ public static final ResourceLocation[] FLAME_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_0.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_1.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_flames_2.png")
+ };
+ public static final ResourceLocation[] DEBRIS_TEXTURES = new ResourceLocation[] {
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_0.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_1.png"),
+ Automobility.rl("textures/entity/automobile/skid_effect/skid_debris_2.png")
+ };
+
+ public SkidEffectModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java
similarity index 59%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java
index 400eb7d..04b781f 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/FrontAttachmentRenderModel.java
@@ -1,14 +1,14 @@
package io.github.foundationgames.automobility.automobile.render.attachment.front;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment;
import io.github.foundationgames.automobility.automobile.render.BaseModel;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.VertexConsumer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.Identifier;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import java.util.NoSuchElementException;
@@ -18,11 +18,11 @@ public class FrontAttachmentRenderModel extends BaseModel {
protected final @Nullable ModelPart ground;
private float groundHeight = 0;
- public FrontAttachmentRenderModel(Function layerFactory, EntityRendererFactory.Context ctx, EntityModelLayer layer) {
+ public FrontAttachmentRenderModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) {
super(layerFactory, ctx, layer);
ModelPart ground;
try {
- ground = ctx.getPart(layer).getChild("ground");
+ ground = ctx.bakeLayer(layer).getChild("ground");
} catch (NoSuchElementException ignored) {
ground = null;
}
@@ -38,12 +38,12 @@ public void resetModel() {
}
@Override
- public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
if (this.ground != null) {
- matrices.push();
+ matrices.pushPose();
matrices.translate(0, groundHeight, 0);
this.ground.render(matrices, vertices, light, overlay, red, green, blue, alpha);
- matrices.pop();
+ matrices.popPose();
}
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java
similarity index 56%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java
index e8b5447..f09982a 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/HarvesterFrontAttachmentModel.java
@@ -2,19 +2,19 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
import org.jetbrains.annotations.Nullable;
public class HarvesterFrontAttachmentModel extends FrontAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/front_attachment/harvester"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/front_attachment/harvester"), "main");
private final @Nullable ModelPart roller;
- public HarvesterFrontAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutout, ctx, MODEL_LAYER);
+ public HarvesterFrontAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
if (this.ground != null) {
this.roller = this.ground.getChild("roller");
@@ -29,9 +29,9 @@ public void setRenderState(@Nullable FrontAttachment attachment, float groundHei
if (this.roller != null) {
if (attachment != null) {
- this.roller.setAngles((float) Math.toRadians(attachment.automobile().getWheelAngle(tickDelta)), 0, 0);
+ this.roller.setRotation((float) Math.toRadians(attachment.automobile().getWheelAngle(tickDelta)), 0, 0);
} else {
- this.roller.setAngles(0, 0, 0);
+ this.roller.setRotation(0, 0, 0);
}
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java
new file mode 100644
index 0000000..2204a65
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/front/MobControllerFrontAttachmentModel.java
@@ -0,0 +1,14 @@
+package io.github.foundationgames.automobility.automobile.render.attachment.front;
+
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class MobControllerFrontAttachmentModel extends FrontAttachmentRenderModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/front_attachment/mob_controller"), "main");
+
+ public MobControllerFrontAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java
similarity index 58%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java
index 476cc9a..cbc5044 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BannerPostRearAttachmentModel.java
@@ -1,27 +1,27 @@
package io.github.foundationgames.automobility.automobile.render.attachment.rear;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.datafixers.util.Pair;
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.BannerPostRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.block.entity.BannerPattern;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.VertexConsumer;
-import net.minecraft.client.render.VertexConsumerProvider;
-import net.minecraft.client.render.block.entity.BannerBlockEntityRenderer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
-import net.minecraft.client.render.model.ModelLoader;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.DyeColor;
-import net.minecraft.util.registry.RegistryEntry;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.blockentity.BannerRenderer;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.client.resources.model.ModelBakery;
+import net.minecraft.core.Holder;
+import net.minecraft.world.item.DyeColor;
+import net.minecraft.world.level.block.entity.BannerPattern;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class BannerPostRearAttachmentModel extends RearAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/banner_post"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/banner_post"), "main");
private final ModelPart fakePole;
private final ModelPart pole;
@@ -33,10 +33,10 @@ public class BannerPostRearAttachmentModel extends RearAttachmentRenderModel {
private boolean renderPole;
private boolean renderFlag;
- private List, DyeColor>> patterns;
+ private List, DyeColor>> patterns;
- public BannerPostRearAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
+ public BannerPostRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
this.fakePole = this.root.getChild("fake_pole");
this.pole = this.root.getChild("pole");
@@ -55,16 +55,16 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
super.setRenderState(attachment, wheelAngle, tickDelta);
float push = attachment == null ? 0 : (float) Math.pow(Math.max(0, attachment.automobile().getHSpeed() * 0.368f), 2);
- this.pole.pitch = -push;
- this.bar.pitch = push;
- this.flagPole.pitch = -push;
- this.flagBar.pitch = push;
+ this.pole.xRot = -push;
+ this.bar.xRot = push;
+ this.flagPole.xRot = -push;
+ this.flagBar.xRot = push;
if (attachment instanceof BannerPostRearAttachment bannerPost) {
this.renderFlag = bannerPost.getBaseColor() != null;
this.patterns = bannerPost.getPatterns();
- this.flag.setAngles(push, this.flag.yaw, 0.05f * (float)Math.sin((attachment.automobile().getTime() + tickDelta) / 20));
+ this.flag.setRotation(push, this.flag.yRot, 0.05f * (float)Math.sin((attachment.automobile().getTime() + tickDelta) / 20));
}
this.renderPole = attachment != null;
@@ -72,17 +72,17 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
}
@Override
- public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ public void renderExtra(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
if (this.renderPole) {
this.pole.visible = true;
- matrices.push();
+ matrices.pushPose();
matrices.translate(0, -1f, 0);
matrices.scale(0.666f, 0.666f, 0.666f);
matrices.translate(0, 1f, 0);
this.pole.render(matrices, vertices, light, overlay, red, green, blue, alpha);
- matrices.pop();
+ matrices.popPose();
this.pole.visible = false;
this.renderPole = false;
}
@@ -90,17 +90,17 @@ public void renderExtra(MatrixStack matrices, VertexConsumer vertices, int light
}
@Override
- public void renderOtherLayer(MatrixStack matrices, VertexConsumerProvider consumers, int light, int overlay) {
+ public void renderOtherLayer(PoseStack matrices, MultiBufferSource consumers, int light, int overlay) {
if (this.renderFlag) {
this.flagPole.visible = true;
- matrices.push();
+ matrices.pushPose();
matrices.translate(0, -1f, 0);
matrices.scale(0.666f, 0.666f, 0.666f);
matrices.translate(0, 1f, 0);
- BannerBlockEntityRenderer.renderCanvas(matrices, consumers, light, overlay, this.flagPole, ModelLoader.BANNER_BASE, true, this.patterns, false);
+ BannerRenderer.renderPatterns(matrices, consumers, light, overlay, this.flagPole, ModelBakery.BANNER_BASE, true, this.patterns, false);
- matrices.pop();
+ matrices.popPose();
this.flagPole.visible = false;
this.renderFlag = false;
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java
new file mode 100644
index 0000000..597e329
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/BlockRearAttachmentModel.java
@@ -0,0 +1,14 @@
+package io.github.foundationgames.automobility.automobile.render.attachment.rear;
+
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class BlockRearAttachmentModel extends RearAttachmentRenderModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/block"), "main");
+
+ public BlockRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java
similarity index 58%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java
index b7f2dfc..5a3f7e5 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.java
@@ -3,19 +3,19 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
import org.jetbrains.annotations.Nullable;
public class ChestRearAttachmentModel extends RearAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/chest"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/chest"), "main");
private final ModelPart lid;
- public ChestRearAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
+ public ChestRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
this.lid = this.root.getChild("lid");
}
@@ -24,15 +24,15 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
super.setRenderState(attachment, wheelAngle, tickDelta);
if (attachment instanceof BaseChestRearAttachment chest) {
- float angle = 1 - chest.lidAnimator.getProgress(tickDelta);
+ float angle = 1 - chest.lidAnimator.getOpenness(tickDelta);
angle = 1 - (angle * angle * angle);
- this.lid.setAngles((float) (angle * Math.PI * 0.5), 0, 0);
+ this.lid.setRotation((float) (angle * Math.PI * 0.5), 0, 0);
}
}
@Override
public void resetModel() {
super.resetModel();
- this.lid.setAngles(0, 0, 0);
+ this.lid.setRotation(0, 0, 0);
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java
similarity index 54%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java
index 8a895f4..a3f5e19 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/GrindstoneRearAttachmentModel.java
@@ -2,19 +2,19 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
import org.jetbrains.annotations.Nullable;
public class GrindstoneRearAttachmentModel extends RearAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/grindstone"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/grindstone"), "main");
private final ModelPart grindstone;
- public GrindstoneRearAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
+ public GrindstoneRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
this.grindstone = this.root.getChild("grindstone");
}
@@ -23,7 +23,7 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
super.setRenderState(attachment, wheelAngle, tickDelta);
if (this.grindstone != null) {
- this.grindstone.setAngles(wheelAngle * 0.25f, 0, 0);
+ this.grindstone.setRotation(wheelAngle * 0.25f, 0, 0);
}
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java
new file mode 100644
index 0000000..a550155
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PassengerSeatRearAttachmentModel.java
@@ -0,0 +1,14 @@
+package io.github.foundationgames.automobility.automobile.render.attachment.rear;
+
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class PassengerSeatRearAttachmentModel extends RearAttachmentRenderModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/passenger_seat"), "main");
+
+ public PassengerSeatRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java
similarity index 67%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java
index 41ab780..f3fe76e 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/PlowRearAttachmentModel.java
@@ -3,22 +3,22 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.ExtendableRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
import org.jetbrains.annotations.Nullable;
import java.util.NoSuchElementException;
public class PlowRearAttachmentModel extends RearAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/plow"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/plow"), "main");
private final ModelPart assembly;
private final ModelPart instrument;
- public PlowRearAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
+ public PlowRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
ModelPart assembly = null, instrument = null;
try {
@@ -36,8 +36,8 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
if (this.assembly != null && this.instrument != null && attachment instanceof ExtendableRearAttachment att) {
float anim = att.extendAnimation(tickDelta);
- this.assembly.setAngles(6.5f * anim, 0, 0);
- this.instrument.setAngles(-3 * anim, 0, 0);
+ this.assembly.setRotation(6.5f * anim, 0, 0);
+ this.instrument.setRotation(-3 * anim, 0, 0);
}
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java
similarity index 66%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java
index d7f9864..3c57a6a 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/RearAttachmentRenderModel.java
@@ -2,11 +2,11 @@
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
import io.github.foundationgames.automobility.automobile.render.BaseModel;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
-import net.minecraft.util.Identifier;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import java.util.NoSuchElementException;
@@ -15,7 +15,7 @@
public class RearAttachmentRenderModel extends BaseModel {
private final @Nullable ModelPart wheels;
- public RearAttachmentRenderModel(Function layerFactory, EntityRendererFactory.Context ctx, EntityModelLayer layer) {
+ public RearAttachmentRenderModel(Function layerFactory, EntityRendererProvider.Context ctx, ModelLayerLocation layer) {
super(layerFactory, ctx, layer);
ModelPart wheels;
try {
@@ -28,7 +28,7 @@ public RearAttachmentRenderModel(Function layerFactory,
public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle, float tickDelta) {
if (this.wheels != null) {
- this.wheels.setAngles(wheelAngle, 0, 0);
+ this.wheels.setRotation(wheelAngle, 0, 0);
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java
similarity index 54%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java
index d47c3b4..c582099 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/attachment/rear/StonecutterRearAttachmentModel.java
@@ -2,19 +2,19 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
-import net.minecraft.client.model.ModelPart;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.model.EntityModelLayer;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.model.geom.ModelPart;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
import org.jetbrains.annotations.Nullable;
public class StonecutterRearAttachmentModel extends RearAttachmentRenderModel {
- public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/stonecutter"), "main");
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/rear_attachment/stonecutter"), "main");
private final ModelPart blade;
- public StonecutterRearAttachmentModel(EntityRendererFactory.Context ctx) {
- super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
+ public StonecutterRearAttachmentModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
this.blade = this.root.getChild("blade");
}
@@ -23,7 +23,7 @@ public void setRenderState(@Nullable RearAttachment attachment, float wheelAngle
super.setRenderState(attachment, wheelAngle, tickDelta);
if (this.blade != null) {
- this.blade.setAngles(wheelAngle * 0.45f, 0, 0);
+ this.blade.setRotation(wheelAngle * 0.45f, 0, 0);
}
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java
new file mode 100644
index 0000000..509f1da
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CopperEngineModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class CopperEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/copper"), "main");
+
+ public CopperEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(180));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java
new file mode 100644
index 0000000..1b5fad0
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/CreativeEngineModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class CreativeEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/creative"), "main");
+
+ public CreativeEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(180));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java
new file mode 100644
index 0000000..3c00bde
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/DiamondEngineModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class DiamondEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/diamond"), "main");
+
+ public DiamondEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java
new file mode 100644
index 0000000..71301b1
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/GoldEngineModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class GoldEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/gold"), "main");
+
+ public GoldEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java
new file mode 100644
index 0000000..f024850
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/IronEngineModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class IronEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/iron"), "main");
+
+ public IronEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java
new file mode 100644
index 0000000..fb7206f
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/engine/StoneEngineModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.engine;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class StoneEngineModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/engine/stone"), "main");
+
+ public StoneEngineModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java
new file mode 100644
index 0000000..f7698b0
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/CARRFrameModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class CARRFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/c_arr"), "main");
+
+ public CARRFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(-90));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java
new file mode 100644
index 0000000..6e78f3c
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/DaBabyFrameModel.java
@@ -0,0 +1,29 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.model.Model;
+import net.minecraft.client.renderer.Sheets;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class DaBabyFrameModel extends Model {
+ // Credit to https://github.com/Sk3leCreeper for model
+ // private final BakedModel model = Myron.getModel(Automobility.id("models/misc/automobile/frame/dababy"));
+
+ public DaBabyFrameModel(EntityRendererProvider.Context ctx) {
+ super(id -> Sheets.solidBlockSheet());
+ }
+
+ @Override
+ public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ /*
+ if (model == null) return;
+ matrices.push();
+ matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180));
+ matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90));
+ matrices.translate(0.1, 0.04, 0);
+ AUtils.renderMyronObj(model, vertices, matrices, light, overlay);
+ matrices.pop();
+ */
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java
new file mode 100644
index 0000000..3d461f7
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/MotorcarFrameModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class MotorcarFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/motorcar"), "main");
+
+ public MotorcarFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityTranslucentCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java
new file mode 100644
index 0000000..bc36640
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/PineappleFrameModel.java
@@ -0,0 +1,21 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class PineappleFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/pineapple"), "main");
+
+ public PineappleFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.scale(2, 2, 2);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java
new file mode 100644
index 0000000..8e0678f
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/RickshawFrameModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class RickshawFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/rickshaw"), "main");
+
+ public RickshawFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java
new file mode 100644
index 0000000..06e5d33
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/ShoppingCartFrameModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class ShoppingCartFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/shopping_cart"), "main");
+
+ public ShoppingCartFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java
new file mode 100644
index 0000000..175aa10
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/StandardFrameModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class StandardFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/standard"), "main");
+
+ public StandardFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(-90));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java
new file mode 100644
index 0000000..365d638
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/frame/TractorFrameModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.frame;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class TractorFrameModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/frame/tractor"), "main");
+
+ public TractorFrameModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java
new file mode 100644
index 0000000..e8f0676
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/item/ItemRenderableAutomobile.java
@@ -0,0 +1,104 @@
+package io.github.foundationgames.automobility.automobile.render.item;
+
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.automobile.AutomobileData;
+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.attachment.front.FrontAttachment;
+import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
+import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile;
+import org.jetbrains.annotations.Nullable;
+
+public class ItemRenderableAutomobile implements RenderableAutomobile {
+ private final AutomobileData reader;
+
+ public ItemRenderableAutomobile(AutomobileData reader) {
+ this.reader = reader;
+ }
+
+ @Override
+ public AutomobileFrame getFrame() {
+ return reader.getFrame();
+ }
+
+ @Override
+ public AutomobileEngine getEngine() {
+ return reader.getEngine();
+ }
+
+ @Override
+ public AutomobileWheel getWheels() {
+ return reader.getWheel();
+ }
+
+ @Override
+ public @Nullable RearAttachment getRearAttachment() {
+ return null;
+ }
+
+ @Override
+ public @Nullable FrontAttachment getFrontAttachment() {
+ return null;
+ }
+
+ @Override
+ public float getAutomobileYaw(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getRearAttachmentYaw(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getWheelAngle(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getSteering(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getSuspensionBounce(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public boolean engineRunning() {
+ return false;
+ }
+
+ @Override
+ public int getBoostTimer() {
+ return 0;
+ }
+
+ @Override
+ public int getTurboCharge() {
+ return 0;
+ }
+
+ @Override
+ public long getTime() {
+ return 0;
+ }
+
+ @Override
+ public boolean automobileOnGround() {
+ return true;
+ }
+
+ @Override
+ public boolean debris() {
+ return false;
+ }
+
+ @Override
+ public Vector3f debrisColor() {
+ return new Vector3f();
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java
new file mode 100644
index 0000000..2c6173f
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/CarriageWheelModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.wheel;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class CarriageWheelModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/carriage"), "main");
+
+ public CarriageWheelModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutoutNoCull, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java
similarity index 50%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java
index 0153347..443b876 100644
--- a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/ConvertibleWheelModel.java
@@ -1,26 +1,21 @@
package io.github.foundationgames.automobility.automobile.render.wheel;
-// import dev.monarkhes.myron.api.Myron;
-import io.github.foundationgames.automobility.Automobility;
-import io.github.foundationgames.automobility.util.AUtils;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.Model;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.VertexConsumer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.model.BakedModel;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.math.Vec3f;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
public class ConvertibleWheelModel extends Model {
// Credit to https://github.com/Sk3leCreeper for model
// private final BakedModel model = Myron.getModel(Automobility.id("models/misc/automobile/wheel/convertible"));
- public ConvertibleWheelModel(EntityRendererFactory.Context ctx) {
- super(id -> RenderLayer.getSolid());
+ public ConvertibleWheelModel(EntityRendererProvider.Context ctx) {
+ super(id -> RenderType.solid());
}
@Override
- public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
+ public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
/*
if (model == null) return;
matrices.push();
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java
new file mode 100644
index 0000000..febc2cd
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/OffRoadWheelModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.wheel;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class OffRoadWheelModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/off_road"), "main");
+
+ public OffRoadWheelModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(-90));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java
new file mode 100644
index 0000000..db9f875
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/StandardWheelModel.java
@@ -0,0 +1,22 @@
+package io.github.foundationgames.automobility.automobile.render.wheel;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class StandardWheelModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/standard"), "main");
+
+ public StandardWheelModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+
+ @Override
+ protected void prepare(PoseStack matrices) {
+ matrices.mulPose(Vector3f.YP.rotationDegrees(-90));
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java
new file mode 100644
index 0000000..3e4c06d
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/SteelWheelModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.wheel;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class SteelWheelModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/steel"), "main");
+
+ public SteelWheelModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java
new file mode 100644
index 0000000..3c6a878
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/TractorWheelModel.java
@@ -0,0 +1,15 @@
+package io.github.foundationgames.automobility.automobile.render.wheel;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.render.BaseModel;
+import net.minecraft.client.model.geom.ModelLayerLocation;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+
+public class TractorWheelModel extends BaseModel {
+ public static final ModelLayerLocation MODEL_LAYER = new ModelLayerLocation(Automobility.rl("automobile/wheel/tractor"), "main");
+
+ public TractorWheelModel(EntityRendererProvider.Context ctx) {
+ super(RenderType::entityCutout, ctx, MODEL_LAYER);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java b/common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java
similarity index 100%
rename from src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java
rename to common/src/main/java/io/github/foundationgames/automobility/automobile/render/wheel/WheelContextReceiver.java
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java
new file mode 100644
index 0000000..67b3699
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutoMechanicTableBlock.java
@@ -0,0 +1,40 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.screen.AutoMechanicTableScreenHandler;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.SimpleMenuProvider;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.phys.BlockHitResult;
+import org.jetbrains.annotations.Nullable;
+
+public class AutoMechanicTableBlock extends Block {
+ public static final Component UI_TITLE = Component.translatable("container.automobility.auto_mechanic_table");
+
+ public AutoMechanicTableBlock(Properties settings) {
+ super(settings);
+ }
+
+ @Override
+ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+ if (world.isClientSide()) {
+ return InteractionResult.SUCCESS;
+ } else {
+ player.openMenu(state.getMenuProvider(world, pos));
+ return InteractionResult.CONSUME;
+ }
+ }
+
+ @Override
+ public @Nullable MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) {
+ return new SimpleMenuProvider((syncId, playerInventory, player) ->
+ new AutoMechanicTableScreenHandler(syncId, playerInventory, ContainerLevelAccess.create(world, pos)), UI_TITLE);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java
new file mode 100644
index 0000000..6c3c2ca
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobileAssemblerBlock.java
@@ -0,0 +1,112 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.EntityBlock;
+import net.minecraft.world.level.block.HorizontalDirectionalBlock;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.BooleanProperty;
+import net.minecraft.world.phys.BlockHitResult;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.Shapes;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import org.jetbrains.annotations.Nullable;
+
+public class AutomobileAssemblerBlock extends HorizontalDirectionalBlock implements EntityBlock {
+ public static final Component USE_CROWBAR_DIALOG = Component.translatable("dialog.automobility.use_crowbar").withStyle(ChatFormatting.GOLD);
+ public static final Component INCOMPLETE_AUTOMOBILE_DIALOG = Component.translatable("dialog.automobility.incomplete_automobile").withStyle(ChatFormatting.RED);
+
+ public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
+
+ private static final VoxelShape BASE = Shapes.or(
+ Block.box(0, 0, 0, 16, 4, 16),
+ Block.box(5, 4, 5, 11, 12, 11));
+
+ private static final VoxelShape NORTH_SOUTH = Shapes.or(BASE,
+ Block.box(0, 8, 6, 16, 12, 10));
+ private static final VoxelShape EAST_WEST = Shapes.or(BASE,
+ Block.box(6, 8, 0, 10, 12, 16));
+
+ public AutomobileAssemblerBlock(Properties settings) {
+ super(settings);
+ this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH).setValue(POWERED, false));
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, world, pos, block, fromPos, notify);
+
+ boolean power = world.hasNeighborSignal(pos);
+ if (power != state.getValue(POWERED)) {
+ world.setBlockAndUpdate(pos, state.setValue(POWERED, power));
+ }
+ }
+
+ @Override
+ public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
+ if (!world.isClientSide() && placer instanceof Player player) {
+ player.displayClientMessage(USE_CROWBAR_DIALOG, true);
+ }
+
+ super.setPlacedBy(world, pos, state, placer, itemStack);
+ }
+
+ @Override
+ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+ if (world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) {
+ return assembler.interact(player, hand);
+ }
+
+ return super.use(state, world, pos, player, hand, hit);
+ }
+
+ @Override
+ public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) {
+ if (!newState.is(this) && world.getBlockEntity(pos) instanceof AutomobileAssemblerBlockEntity assembler) {
+ assembler.dropParts();
+ }
+
+ super.onRemove(state, world, pos, newState, moved);
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ return switch (state.getValue(FACING)) {
+ case EAST, WEST -> EAST_WEST;
+ default -> NORTH_SOUTH;
+ };
+ }
+
+ @Nullable
+ @Override
+ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
+ return super.getStateForPlacement(ctx).setValue(FACING, ctx.getHorizontalDirection().getOpposite());
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(FACING, POWERED);
+ }
+
+ @Nullable
+ @Override
+ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
+ return new AutomobileAssemblerBlockEntity(pos, state);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java
new file mode 100644
index 0000000..274f5fe
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java
@@ -0,0 +1,73 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity;
+import io.github.foundationgames.automobility.item.DashPanelItem;
+import io.github.foundationgames.automobility.item.SlopeBlockItem;
+import io.github.foundationgames.automobility.item.SteepSlopeBlockItem;
+import io.github.foundationgames.automobility.item.TooltipBlockItem;
+import io.github.foundationgames.automobility.platform.Platform;
+import io.github.foundationgames.automobility.util.AUtils;
+import io.github.foundationgames.automobility.util.Eventual;
+import io.github.foundationgames.automobility.util.RegistryQueue;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.Registry;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.CreativeModeTab;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.SoundType;
+import net.minecraft.world.level.block.entity.BlockEntityType;
+import net.minecraft.world.level.block.state.BlockBehaviour;
+import net.minecraft.world.level.material.Material;
+
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public enum AutomobilityBlocks {;
+ public static final Eventual AUTO_MECHANIC_TABLE = register("auto_mechanic_table", () -> new AutoMechanicTableBlock(BlockBehaviour.Properties.copy(Blocks.COPPER_BLOCK)), Automobility.GROUP);
+ public static final Eventual AUTOMOBILE_ASSEMBLER = register("automobile_assembler", () -> new AutomobileAssemblerBlock(BlockBehaviour.Properties.copy(Blocks.ANVIL)), Automobility.GROUP);
+
+ public static final Eventual SLOPE = register("slope", () -> new SlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SlopeBlockItem(b, new Item.Properties().tab(Automobility.GROUP)));
+ public static final Eventual STEEP_SLOPE = register("steep_slope", () -> new SteepSlopeBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK), false), b -> new SteepSlopeBlockItem(b, new Item.Properties().tab(Automobility.GROUP)));
+
+ public static final Eventual SLOPE_WITH_DASH_PANEL = register("slope_with_dash_panel", () -> new SlopeWithDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK)
+ .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED))));
+ public static final Eventual STEEP_SLOPE_WITH_DASH_PANEL = register("steep_slope_with_dash_panel", () -> new SteepSlopeWithDashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK)
+ .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED))));
+ public static final Eventual DASH_PANEL = register("dash_panel", () -> new DashPanelBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK)
+ .lightLevel(s -> s.getValue(DashPanelBlock.POWERED) ? 0 : 1).emissiveRendering((s, l, p) -> !s.getValue(DashPanelBlock.POWERED)).noCollission()), b -> new DashPanelItem(b, new Item.Properties().tab(Automobility.GROUP)));
+
+ public static final Eventual GRASS_OFF_ROAD = register("grass_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.GRASS_BLOCK).noCollission(), AUtils.colorFromInt(0x406918)), Automobility.GROUP);
+ public static final Eventual DIRT_OFF_ROAD = register("dirt_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.DIRT).noCollission(), AUtils.colorFromInt(0x594227)), Automobility.GROUP);
+ public static final Eventual SAND_OFF_ROAD = register("sand_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.SAND).noCollission(), AUtils.colorFromInt(0xC2B185)), Automobility.GROUP);
+ public static final Eventual SNOW_OFF_ROAD = register("snow_off_road", () -> new OffRoadBlock(BlockBehaviour.Properties.copy(Blocks.SNOW).noCollission(), AUtils.colorFromInt(0xD0E7ED)), Automobility.GROUP);
+
+ public static final Eventual LAUNCH_GEL = register("launch_gel", () -> new LaunchGelBlock(BlockBehaviour.Properties.of(Material.CLAY).strength(0.1f).sound(SoundType.HONEY_BLOCK).noCollission()), Automobility.GROUP);
+
+ public static final Eventual ALLOW = register("allow", () -> new Block(BlockBehaviour.Properties.copy(Blocks.BARRIER).sound(SoundType.METAL)),
+ b -> new TooltipBlockItem(b, Component.translatable("tooltip.block.automobility.allow").withStyle(ChatFormatting.AQUA), new Item.Properties()));
+
+ public static final Eventual> AUTOMOBILE_ASSEMBLER_ENTITY = RegistryQueue.register(Registry.BLOCK_ENTITY_TYPE,
+ Automobility.rl("automobile_assembler"), () -> Platform.get().blockEntity(AutomobileAssemblerBlockEntity::new, AUTOMOBILE_ASSEMBLER.require()));
+
+ public static void init() {
+ }
+
+ public static Eventual register(String name, Supplier block) {
+ return RegistryQueue.register(Registry.BLOCK, Automobility.rl(name), block);
+ }
+
+ public static Eventual register(String name, Supplier block, CreativeModeTab group) {
+ return register(name, block, b -> new BlockItem(b, new Item.Properties().tab(group)));
+ }
+
+ public static Eventual register(String name, Supplier block, Function item) {
+ var blockPromise = register(name, block);
+ RegistryQueue.register(Registry.ITEM, Automobility.rl(name), () -> item.apply(blockPromise.require()));
+
+ return blockPromise;
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java
new file mode 100644
index 0000000..a3ea4ba
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/DashPanelBlock.java
@@ -0,0 +1,121 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.entity.AutomobilityEntities;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.effect.MobEffectInstance;
+import net.minecraft.world.effect.MobEffects;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.LevelAccessor;
+import net.minecraft.world.level.LevelReader;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.HorizontalDirectionalBlock;
+import net.minecraft.world.level.block.SimpleWaterloggedBlock;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.BooleanProperty;
+import net.minecraft.world.level.material.FluidState;
+import net.minecraft.world.level.material.Fluids;
+import net.minecraft.world.phys.Vec3;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import org.jetbrains.annotations.Nullable;
+
+public class DashPanelBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock {
+ public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
+ public static final BooleanProperty LEFT = BooleanProperty.create("left");
+ public static final BooleanProperty RIGHT = BooleanProperty.create("right");
+ public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
+
+ public static final VoxelShape SHAPE = box(0, 0, 0, 16, 1, 16);
+
+ public DashPanelBlock(Properties settings) {
+ super(settings);
+ registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH)
+ .setValue(LEFT, false).setValue(RIGHT, false)
+ .setValue(POWERED, false).setValue(WATERLOGGED, false));
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(FACING, LEFT, RIGHT, POWERED, WATERLOGGED);
+ }
+
+ @Override
+ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
+ return level.getBlockState(pos.below()).isFaceSturdy(level, pos.below(), Direction.UP);
+ }
+
+ @Nullable
+ @Override
+ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
+ return super.getStateForPlacement(ctx).setValue(FACING, ctx.getHorizontalDirection()).setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER));
+ }
+
+ @Override
+ public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
+ var lState = world.getBlockState(pos.relative(state.getValue(FACING).getCounterClockWise(Direction.Axis.Y)));
+ var rState = world.getBlockState(pos.relative(state.getValue(FACING).getClockWise(Direction.Axis.Y)));
+ boolean left = lState.is(this) && (lState.getValue(POWERED) == state.getValue(POWERED));
+ boolean right = rState.is(this) && (rState.getValue(POWERED) == state.getValue(POWERED));
+
+ return state.setValue(LEFT, left).setValue(RIGHT, right);
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, level, pos, block, fromPos, notify);
+
+ boolean levelPwr = level.hasNeighborSignal(pos);
+ boolean selfPwr = state.getValue(POWERED);
+
+ if (levelPwr != selfPwr) {
+ level.setBlockAndUpdate(pos, state.setValue(POWERED, levelPwr));
+ }
+
+ if (!canSurvive(state, level, pos)) {
+ level.destroyBlock(pos, true);
+ }
+ }
+
+ @Override
+ public FluidState getFluidState(BlockState state) {
+ return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
+ }
+
+ @Override
+ public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
+ super.entityInside(state, world, pos, entity);
+ onCollideWithDashPanel(state, entity);
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ return SHAPE;
+ }
+
+ public static void onCollideWithDashPanel(@Nullable BlockState panelState, Entity entity) {
+ if (panelState != null && panelState.getValue(POWERED)) {
+ return;
+ }
+
+ if (entity instanceof AutomobileEntity auto) {
+ auto.boost(0.45f, 50);
+ } else if (entity.getType().is(AutomobilityEntities.DASH_PANEL_BOOSTABLES)) {
+ if (entity instanceof LivingEntity living) {
+ living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 40, 6, true, false, false));
+ }
+ double yaw = Math.toRadians(-entity.getYRot());
+ var vel = new Vec3(Math.sin(yaw), 0, Math.cos(yaw));
+ entity.push(vel.x, vel.y, vel.z);
+ }
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java
new file mode 100644
index 0000000..eda77e7
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/LaunchGelBlock.java
@@ -0,0 +1,53 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.LevelReader;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.VoxelShape;
+
+public class LaunchGelBlock extends Block {
+ public static final VoxelShape SHAPE = box(0, 0, 0, 16, 1, 16);
+
+ public LaunchGelBlock(Properties settings) {
+ super(settings);
+ }
+
+ public boolean canExistAt(LevelReader world, BlockPos pos) {
+ return world.getBlockState(pos.below()).isFaceSturdy(world, pos, Direction.UP);
+ }
+
+ @Override
+ public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
+ super.entityInside(state, world, pos, entity);
+
+ if (entity instanceof AutomobileEntity automobile && automobile.automobileOnGround()) {
+ automobile.boost(0.14f, 7);
+ }
+ }
+
+ @Override
+ public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
+ return canExistAt(world, pos);
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, world, pos, block, fromPos, notify);
+
+ if (!canExistAt(world, pos)) {
+ world.destroyBlock(pos, true);
+ }
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ return SHAPE;
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java
new file mode 100644
index 0000000..2e95ed0
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/OffRoadBlock.java
@@ -0,0 +1,81 @@
+package io.github.foundationgames.automobility.block;
+
+import com.mojang.math.Vector3f;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.LevelReader;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+import net.minecraft.world.level.block.state.properties.IntegerProperty;
+import net.minecraft.world.level.material.PushReaction;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import org.jetbrains.annotations.Nullable;
+
+public class OffRoadBlock extends Block {
+ public static final VoxelShape ONE_LAYER_SHAPE = box(0, 0, 0, 16, 2, 16);
+ public static final VoxelShape TWO_LAYER_SHAPE = box(0, 0, 0, 16, 4, 16);
+ public static final VoxelShape THREE_LAYER_SHAPE = box(0, 0, 0, 16, 6, 16);
+
+ public static final IntegerProperty LAYERS = IntegerProperty.create("layers", 1, 3);
+
+ public final Vector3f color;
+
+ public OffRoadBlock(Properties settings, Vector3f color) {
+ super(settings);
+ registerDefaultState(defaultBlockState().setValue(LAYERS, 1));
+ this.color = color;
+ }
+
+ @Nullable
+ @Override
+ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
+ var state = ctx.getLevel().getBlockState(ctx.getClickedPos());
+ if (state.is(this) && state.getValue(LAYERS) < 3) {
+ return state.setValue(LAYERS, state.getValue(LAYERS) + 1);
+ }
+ return super.getStateForPlacement(ctx);
+ }
+
+ @Override
+ public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
+ return state.getValue(LAYERS) < 3 && context.getItemInHand().is(this.asItem());
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, world, pos, block, fromPos, notify);
+ if (!canSurvive(state, world, pos)) {
+ world.destroyBlock(pos, true);
+ }
+ }
+
+ @Override
+ public PushReaction getPistonPushReaction(BlockState state) {
+ return PushReaction.DESTROY;
+ }
+
+ @Override
+ public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
+ return world.getBlockState(pos.below()).isFaceSturdy(world, pos.below(), Direction.UP);
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ return switch (state.getValue(LAYERS)) {
+ case 2 -> TWO_LAYER_SHAPE;
+ case 3 -> THREE_LAYER_SHAPE;
+ default -> ONE_LAYER_SHAPE;
+ };
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(LAYERS);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java
new file mode 100644
index 0000000..934b2de
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeBlock.java
@@ -0,0 +1,203 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.item.SlopePlacementContext;
+import io.github.foundationgames.automobility.util.AUtils;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.HorizontalDirectionalBlock;
+import net.minecraft.world.level.block.SimpleWaterloggedBlock;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.BooleanProperty;
+import net.minecraft.world.level.block.state.properties.EnumProperty;
+import net.minecraft.world.level.block.state.properties.Half;
+import net.minecraft.world.level.material.FluidState;
+import net.minecraft.world.level.material.Fluids;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.Shapes;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+
+public class SlopeBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock {
+ public static final VoxelShape NORTH_BOTTOM_SHAPE;
+ public static final VoxelShape SOUTH_BOTTOM_SHAPE;
+ public static final VoxelShape EAST_BOTTOM_SHAPE;
+ public static final VoxelShape WEST_BOTTOM_SHAPE;
+ public static final VoxelShape NORTH_TOP_SHAPE;
+ public static final VoxelShape SOUTH_TOP_SHAPE;
+ public static final VoxelShape EAST_TOP_SHAPE;
+ public static final VoxelShape WEST_TOP_SHAPE;
+
+ public static final VoxelShape OLD_NORTH_BOTTOM_SHAPE;
+ public static final VoxelShape OLD_SOUTH_BOTTOM_SHAPE;
+ public static final VoxelShape OLD_EAST_BOTTOM_SHAPE;
+ public static final VoxelShape OLD_WEST_BOTTOM_SHAPE;
+ public static final VoxelShape OLD_NORTH_TOP_SHAPE;
+ public static final VoxelShape OLD_SOUTH_TOP_SHAPE;
+ public static final VoxelShape OLD_EAST_TOP_SHAPE;
+ public static final VoxelShape OLD_WEST_TOP_SHAPE;
+
+ public static final EnumProperty HALF = BlockStateProperties.HALF;
+ public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
+
+ protected final boolean old;
+
+ public SlopeBlock(Properties settings, boolean old) {
+ super(settings);
+ this.old = old;
+ registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(HALF, Half.BOTTOM).setValue(WATERLOGGED, false));
+ }
+
+ @Nullable
+ @Override
+ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
+ return ctx instanceof SlopePlacementContext slopeCtx ?
+ super.getStateForPlacement(ctx)
+ .setValue(FACING, slopeCtx.getSlopeFacing())
+ .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER))
+ .setValue(HALF, slopeCtx.getSlopeHalf())
+ :
+ super.getStateForPlacement(ctx)
+ .setValue(FACING, ctx.getHorizontalDirection().getOpposite())
+ .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER))
+ .setValue(HALF, ctx.getClickLocation().y - ctx.getClickedPos().getY() > 0.5 ? Half.TOP : Half.BOTTOM);
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(FACING, HALF, WATERLOGGED);
+ }
+
+ @Override
+ public FluidState getFluidState(BlockState state) {
+ return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ if (old) {
+ return switch (state.getValue(HALF)) {
+ case BOTTOM -> switch (state.getValue(FACING)) {
+ case NORTH -> OLD_NORTH_BOTTOM_SHAPE;
+ case SOUTH -> OLD_SOUTH_BOTTOM_SHAPE;
+ case WEST -> OLD_WEST_BOTTOM_SHAPE;
+ case EAST -> OLD_EAST_BOTTOM_SHAPE;
+ default -> Shapes.empty();
+ };
+ case TOP -> switch (state.getValue(FACING)) {
+ case NORTH -> OLD_NORTH_TOP_SHAPE;
+ case SOUTH -> OLD_SOUTH_TOP_SHAPE;
+ case WEST -> OLD_WEST_TOP_SHAPE;
+ case EAST -> OLD_EAST_TOP_SHAPE;
+ default -> Shapes.empty();
+ };
+ default -> Shapes.empty();
+ };
+ } else {
+ return switch (state.getValue(HALF)) {
+ case BOTTOM -> switch (state.getValue(FACING)) {
+ case NORTH -> NORTH_BOTTOM_SHAPE;
+ case SOUTH -> SOUTH_BOTTOM_SHAPE;
+ case WEST -> WEST_BOTTOM_SHAPE;
+ case EAST -> EAST_BOTTOM_SHAPE;
+ default -> Shapes.empty();
+ };
+ case TOP -> switch (state.getValue(FACING)) {
+ case NORTH -> NORTH_TOP_SHAPE;
+ case SOUTH -> SOUTH_TOP_SHAPE;
+ case WEST -> WEST_TOP_SHAPE;
+ case EAST -> EAST_TOP_SHAPE;
+ default -> Shapes.empty();
+ };
+ default -> Shapes.empty();
+ };
+ }
+ }
+
+ public static VoxelShape slopeStep(Direction dir, double height) {
+ return switch (dir) {
+ case NORTH -> Block.box(0, 0, 0, 16, height, 0.5);
+ case SOUTH -> Block.box(0, 0, 15.5, 16, height, 16);
+ case EAST -> Block.box(15.5, 0, 0, 16, height, 16);
+ case WEST -> Block.box(0, 0, 0, 0.5, height, 16);
+ default -> Shapes.empty();
+ };
+ }
+
+ static {
+ var shapes = new ArrayList();
+ for (var dir : AUtils.HORIZONTAL_DIRS) {
+ for (int i = 0; i < 2; i++) {
+ double ox = switch (dir) {
+ case WEST -> 0.5;
+ case EAST -> -0.5;
+ default -> 0;
+ };
+ double oz = switch (dir) {
+ case NORTH -> 0.5;
+ case SOUTH -> -0.5;
+ default -> 0;
+ };
+ var finalShape = Shapes.empty();
+ for (int j = 0; j < 32; j++) {
+ finalShape = Shapes.or(finalShape, slopeStep(dir, (i * 8) + (j * 0.25)).move((ox * j) / 16, 0, (oz * j) / 16));
+ }
+ shapes.add(finalShape);
+ }
+ }
+ NORTH_BOTTOM_SHAPE = shapes.get(0);
+ NORTH_TOP_SHAPE = shapes.get(1);
+ SOUTH_BOTTOM_SHAPE = shapes.get(2);
+ SOUTH_TOP_SHAPE = shapes.get(3);
+ EAST_BOTTOM_SHAPE = shapes.get(4);
+ EAST_TOP_SHAPE = shapes.get(5);
+ WEST_BOTTOM_SHAPE = shapes.get(6);
+ WEST_TOP_SHAPE = shapes.get(7);
+
+ // OLD SLOPE SHAPES
+ shapes.clear();
+ for (var dir : AUtils.HORIZONTAL_DIRS) {
+ for (int i = 0; i < 2; i++) {
+ double ox = switch (dir) {
+ case WEST -> 0.5;
+ case EAST -> -0.5;
+ default -> 0;
+ };
+ double oz = switch (dir) {
+ case NORTH -> 0.5;
+ case SOUTH -> -0.5;
+ default -> 0;
+ };
+ var shape = switch (dir) {
+ case NORTH -> Block.box(0, -1.5, 0, 16, 0.5, 0.5);
+ case SOUTH -> Block.box(0, -1.5, 15.5, 16, 0.5, 16);
+ case EAST -> Block.box(15.5, -1.5, 0, 16, 0.5, 16);
+ case WEST -> Block.box(0, -1.5, 0, 0.5, 0.5, 16);
+ default -> Shapes.empty();
+ };
+ shape = shape.move(0, i * 0.5, 0);
+ var finalShape = shape;
+ for (int j = 1; j < 32; j++) {
+ finalShape = Shapes.or(finalShape, shape.move((ox * j) / 16, (0.25 * j) / 16, (oz * j) / 16));
+ }
+ shapes.add(finalShape);
+ }
+ }
+ OLD_NORTH_BOTTOM_SHAPE = shapes.get(0);
+ OLD_NORTH_TOP_SHAPE = shapes.get(1);
+ OLD_SOUTH_BOTTOM_SHAPE = shapes.get(2);
+ OLD_SOUTH_TOP_SHAPE = shapes.get(3);
+ OLD_EAST_BOTTOM_SHAPE = shapes.get(4);
+ OLD_EAST_TOP_SHAPE = shapes.get(5);
+ OLD_WEST_BOTTOM_SHAPE = shapes.get(6);
+ OLD_WEST_TOP_SHAPE = shapes.get(7);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java
new file mode 100644
index 0000000..e84f8aa
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/SlopeWithDashPanelBlock.java
@@ -0,0 +1,47 @@
+package io.github.foundationgames.automobility.block;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+
+public class SlopeWithDashPanelBlock extends SlopeBlock {
+ public SlopeWithDashPanelBlock(Properties settings) {
+ super(settings, false);
+
+ registerDefaultState(defaultBlockState().setValue(DashPanelBlock.POWERED, false));
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(DashPanelBlock.POWERED);
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, level, pos, block, fromPos, notify);
+
+ boolean levelPwr = level.hasNeighborSignal(pos);
+ boolean selfPwr = state.getValue(DashPanelBlock.POWERED);
+
+ if (levelPwr != selfPwr) {
+ level.setBlockAndUpdate(pos, state.setValue(DashPanelBlock.POWERED, levelPwr));
+ }
+ }
+
+ @Override
+ public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) {
+ return new ItemStack(AutomobilityBlocks.DASH_PANEL.require());
+ }
+
+ @Override
+ public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
+ super.entityInside(state, world, pos, entity);
+ DashPanelBlock.onCollideWithDashPanel(state, entity);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java
new file mode 100644
index 0000000..791e791
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeBlock.java
@@ -0,0 +1,147 @@
+package io.github.foundationgames.automobility.block;
+
+import io.github.foundationgames.automobility.item.SlopePlacementContext;
+import io.github.foundationgames.automobility.util.AUtils;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.HorizontalDirectionalBlock;
+import net.minecraft.world.level.block.SimpleWaterloggedBlock;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.BooleanProperty;
+import net.minecraft.world.level.material.FluidState;
+import net.minecraft.world.level.material.Fluids;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.Shapes;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+
+public class SteepSlopeBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock {
+ public static final VoxelShape NORTH_SHAPE;
+ public static final VoxelShape SOUTH_SHAPE;
+ public static final VoxelShape EAST_SHAPE;
+ public static final VoxelShape WEST_SHAPE;
+
+ public static final VoxelShape OLD_NORTH_SHAPE;
+ public static final VoxelShape OLD_SOUTH_SHAPE;
+ public static final VoxelShape OLD_EAST_SHAPE;
+ public static final VoxelShape OLD_WEST_SHAPE;
+
+ public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
+
+ protected final boolean old;
+
+ public SteepSlopeBlock(Properties settings, boolean old) {
+ super(settings.noOcclusion());
+ this.old = old;
+ registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
+ }
+
+ @Nullable
+ @Override
+ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
+ return ctx instanceof SlopePlacementContext slopeCtx ?
+ super.getStateForPlacement(ctx)
+ .setValue(FACING, slopeCtx.getSlopeFacing())
+ .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER))
+ :
+ super.getStateForPlacement(ctx)
+ .setValue(FACING, ctx.getHorizontalDirection().getOpposite())
+ .setValue(WATERLOGGED, ctx.getLevel().getBlockState(ctx.getClickedPos()).is(Blocks.WATER));
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(FACING, WATERLOGGED);
+ }
+
+ @Override
+ public FluidState getFluidState(BlockState state) {
+ return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
+ }
+
+ @Override
+ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
+ if (old) {
+ return switch (state.getValue(FACING)) {
+ case NORTH -> OLD_NORTH_SHAPE;
+ case SOUTH -> OLD_SOUTH_SHAPE;
+ case WEST -> OLD_WEST_SHAPE;
+ case EAST -> OLD_EAST_SHAPE;
+ default -> Shapes.empty();
+ };
+ } else {
+ return switch (state.getValue(FACING)) {
+ case NORTH -> NORTH_SHAPE;
+ case SOUTH -> SOUTH_SHAPE;
+ case WEST -> WEST_SHAPE;
+ case EAST -> EAST_SHAPE;
+ default -> Shapes.empty();
+ };
+ }
+ }
+
+ static {
+ var shapes = new ArrayList();
+ for (var dir : AUtils.HORIZONTAL_DIRS) {
+ double ox = switch (dir) {
+ case WEST -> 0.5;
+ case EAST -> -0.5;
+ default -> 0;
+ };
+ double oz = switch (dir) {
+ case NORTH -> 0.5;
+ case SOUTH -> -0.5;
+ default -> 0;
+ };
+ var finalShape = Shapes.empty();
+ for (int j = 1; j < 32; j++) {
+ finalShape = Shapes.or(finalShape, SlopeBlock.slopeStep(dir, (j * 0.5)).move((ox * j) / 16, 0, (oz * j) / 16));
+ }
+ shapes.add(finalShape);
+ }
+ NORTH_SHAPE = shapes.get(0);
+ SOUTH_SHAPE = shapes.get(1);
+ EAST_SHAPE = shapes.get(2);
+ WEST_SHAPE = shapes.get(3);
+
+ // OLD SLOPE SHAPES
+ shapes.clear();
+ for (var dir : AUtils.HORIZONTAL_DIRS) {
+ double ox = switch (dir) {
+ case WEST -> 0.5;
+ case EAST -> -0.5;
+ default -> 0;
+ };
+ double oz = switch (dir) {
+ case NORTH -> 0.5;
+ case SOUTH -> -0.5;
+ default -> 0;
+ };
+ var shape = switch (dir) {
+ case NORTH -> Block.box(0, -1.5, 0, 16, 0.5, 0.5);
+ case SOUTH -> Block.box(0, -1.5, 15.5, 16, 0.5, 16);
+ case EAST -> Block.box(15.5, -1.5, 0, 16, 0.5, 16);
+ case WEST -> Block.box(0, -1.5, 0, 0.5, 0.5, 16);
+ default -> Shapes.empty();
+ };
+ var finalShape = shape;
+ for (int i = 1; i < 32; i++) {
+ finalShape = Shapes.or(finalShape, shape.move((ox * i) / 16, (0.5 * i) / 16, (oz * i) / 16));
+ }
+ shapes.add(finalShape);
+ }
+ OLD_NORTH_SHAPE = shapes.get(0);
+ OLD_SOUTH_SHAPE = shapes.get(1);
+ OLD_EAST_SHAPE = shapes.get(2);
+ OLD_WEST_SHAPE = shapes.get(3);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java
new file mode 100644
index 0000000..b3baf76
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/SteepSlopeWithDashPanelBlock.java
@@ -0,0 +1,47 @@
+package io.github.foundationgames.automobility.block;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.StateDefinition;
+
+public class SteepSlopeWithDashPanelBlock extends SteepSlopeBlock {
+ public SteepSlopeWithDashPanelBlock(Properties settings) {
+ super(settings, false);
+
+ registerDefaultState(defaultBlockState().setValue(DashPanelBlock.POWERED, false));
+ }
+
+ @Override
+ protected void createBlockStateDefinition(StateDefinition.Builder builder) {
+ super.createBlockStateDefinition(builder);
+ builder.add(DashPanelBlock.POWERED);
+ }
+
+ @Override
+ public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
+ super.neighborChanged(state, level, pos, block, fromPos, notify);
+
+ boolean levelPwr = level.hasNeighborSignal(pos);
+ boolean selfPwr = state.getValue(DashPanelBlock.POWERED);
+
+ if (levelPwr != selfPwr) {
+ level.setBlockAndUpdate(pos, state.setValue(DashPanelBlock.POWERED, levelPwr));
+ }
+ }
+
+ @Override
+ public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) {
+ return new ItemStack(AutomobilityBlocks.DASH_PANEL.require());
+ }
+
+ @Override
+ public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
+ super.entityInside(state, world, pos, entity);
+ DashPanelBlock.onCollideWithDashPanel(state, entity);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java b/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java
new file mode 100644
index 0000000..bc77724
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/AutomobileAssemblerBlockEntity.java
@@ -0,0 +1,345 @@
+package io.github.foundationgames.automobility.block.entity;
+
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.automobile.AutomobileEngine;
+import io.github.foundationgames.automobility.automobile.AutomobileFrame;
+import io.github.foundationgames.automobility.automobile.AutomobileStats;
+import io.github.foundationgames.automobility.automobile.AutomobileWheel;
+import io.github.foundationgames.automobility.automobile.attachment.front.FrontAttachment;
+import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
+import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile;
+import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock;
+import io.github.foundationgames.automobility.block.AutomobilityBlocks;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.item.AutomobileEngineItem;
+import io.github.foundationgames.automobility.item.AutomobileFrameItem;
+import io.github.foundationgames.automobility.item.AutomobileWheelItem;
+import io.github.foundationgames.automobility.item.AutomobilityItems;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.particles.ParticleTypes;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.protocol.Packet;
+import net.minecraft.network.protocol.game.ClientGamePacketListener;
+import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
+import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.item.ItemEntity;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.gameevent.GameEvent;
+import net.minecraft.world.phys.Vec3;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AutomobileAssemblerBlockEntity extends BlockEntity implements RenderableAutomobile {
+ protected AutomobileFrame frame = AutomobileFrame.EMPTY;
+ protected AutomobileEngine engine = AutomobileEngine.EMPTY;
+ protected AutomobileWheel wheel = AutomobileWheel.EMPTY;
+ protected int wheelCount = 0;
+
+ public final List label = new ArrayList<>();
+ protected final AutomobileStats stats = new AutomobileStats();
+
+ public AutomobileAssemblerBlockEntity(BlockPos pos, BlockState state) {
+ super(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER_ENTITY.require(), pos, state);
+ }
+
+ @Override
+ public AutomobileFrame getFrame() {
+ return frame;
+ }
+
+ @Override
+ public AutomobileWheel getWheels() {
+ return wheel;
+ }
+
+ @Override
+ public AutomobileEngine getEngine() {
+ return engine;
+ }
+
+ @Override
+ public @Nullable RearAttachment getRearAttachment() {
+ return null;
+ }
+
+ @Override
+ public @Nullable FrontAttachment getFrontAttachment() {
+ return null;
+ }
+
+ private void partChanged() {
+ this.sync();
+ this.setChanged();
+ this.level.gameEvent(GameEvent.BLOCK_CHANGE, this.getBlockPos(), new GameEvent.Context(null, this.getBlockState()));
+ }
+
+ protected InteractionResult handleItemInteract(Player player, ItemStack stack) {
+ // Returns success on the server since the client is never 100% confident that the action was valid
+ // Subsequent handling is performed with the action result
+
+ if (stack.is(AutomobilityItems.CROWBAR.require())) {
+ if (!level.isClientSide()) {
+ this.dropParts();
+ this.partChanged();
+ return InteractionResult.SUCCESS;
+ }
+ return InteractionResult.PASS;
+ }
+ if (this.frame.isEmpty() && stack.getItem() instanceof AutomobileFrameItem frameItem) {
+ if (!level.isClientSide()) {
+ this.frame = frameItem.getComponent(stack);
+ if (!player.isCreative()) {
+ stack.shrink(1);
+ }
+ this.partChanged();
+ return InteractionResult.SUCCESS;
+ }
+ return InteractionResult.PASS;
+ }
+ if (!this.frame.isEmpty()) {
+ if (this.engine.isEmpty() && stack.getItem() instanceof AutomobileEngineItem engineItem) {
+ if (!level.isClientSide()) {
+ this.engine = engineItem.getComponent(stack);
+ if (!player.isCreative()) {
+ stack.shrink(1);
+ }
+ this.partChanged();
+ return InteractionResult.SUCCESS;
+ }
+ return InteractionResult.PASS;
+ }
+ if (stack.getItem() instanceof AutomobileWheelItem wheelItem) {
+ if (!level.isClientSide()) {
+ var wheelType = wheelItem.getComponent(stack);
+ if (this.wheel.isEmpty()) {
+ this.wheel = wheelType;
+ this.wheelCount = 0; // Fix wheel count if ever invalid
+ }
+ if (this.wheel == wheelType && this.wheelCount < this.frame.model().wheelBase().wheelCount) {
+ this.wheelCount++;
+ if (!player.isCreative()) {
+ stack.shrink(1);
+ }
+ this.partChanged();
+ return InteractionResult.SUCCESS;
+ }
+ } else {
+ return InteractionResult.PASS;
+ }
+ }
+ }
+ if (!this.level.isClientSide() && stack.is(AutomobilityItems.FRONT_ATTACHMENT.require()) || stack.is(AutomobilityItems.REAR_ATTACHMENT.require())) {
+ player.displayClientMessage(AutomobileAssemblerBlock.INCOMPLETE_AUTOMOBILE_DIALOG, true);
+ }
+
+ return InteractionResult.FAIL;
+ }
+
+ public InteractionResult interact(Player player, InteractionHand hand) {
+ var stack = player.getItemInHand(hand);
+ var result = this.handleItemInteract(player, stack);
+
+ if (!this.level.isClientSide() && result == InteractionResult.SUCCESS) {
+ if (!isComplete()) {
+ level.playSound(null, this.worldPosition, SoundEvents.COPPER_PLACE, SoundSource.BLOCKS, 0.7f, 0.6f + (this.level.random.nextFloat() * 0.15f));
+ }
+
+ tryConstructAutomobile();
+ return InteractionResult.SUCCESS;
+ }
+ return result;
+ }
+
+ protected Vec3 centerPos() {
+ return new Vec3(this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.75, this.worldPosition.getZ() + 0.5);
+ }
+
+ public boolean isComplete() {
+ return !this.frame.isEmpty() &&
+ !this.engine.isEmpty() &&
+ ((!this.wheel.isEmpty()) && (this.wheelCount >= this.frame.model().wheelBase().wheelCount));
+ }
+
+ public void tryConstructAutomobile() {
+ if (this.isComplete()) {
+ var pos = this.centerPos();
+ var auto = new AutomobileEntity(this.level);
+ auto.moveTo(pos.x, pos.y, pos.z, this.getAutomobileYaw(0), 0);
+ auto.setComponents(this.frame, this.wheel, this.engine);
+ level.addFreshEntity(auto);
+
+ level.players().forEach(p -> {
+ if (p instanceof ServerPlayer player && p.blockPosition().distSqr(this.worldPosition) < 80000) {
+ player.connection.send(new ClientboundLevelParticlesPacket(ParticleTypes.EXPLOSION, false, pos.x, pos.y + 0.47, pos.z, 0, 0, 0, 0, 1));
+ }
+ });
+ level.playSound(null, this.worldPosition, SoundEvents.ANVIL_PLACE, SoundSource.BLOCKS, 0.23f, 0.5f);
+
+ this.clear();
+ }
+ }
+
+ public void dropParts() {
+ var pos = this.centerPos();
+
+ this.level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.require().createStack(this.getFrame())));
+ this.level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.require().createStack(this.getEngine())));
+
+ var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.require().createStack(this.getWheels());
+ wheelStack.setCount(this.wheelCount);
+ this.level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, wheelStack));
+
+ this.clear();
+ }
+
+ public void clear() {
+ this.frame = AutomobileFrame.EMPTY;
+ this.wheel = AutomobileWheel.EMPTY;
+ this.engine = AutomobileEngine.EMPTY;
+ this.wheelCount = 0;
+ }
+
+ private boolean hasAllParts() {
+ return !this.frame.isEmpty() && !this.wheel.isEmpty() && !this.engine.isEmpty();
+ }
+
+ private void onComponentsUpdated() {
+ if (level == null || level.isClientSide()) {
+ this.label.clear();
+ if (this.hasAllParts()) {
+ this.stats.from(this.frame, this.wheel, this.engine);
+ this.stats.appendTexts(this.label, this.stats);
+ }
+ }
+ }
+
+ private void sync() {
+ if (this.level instanceof ServerLevel sWorld) {
+ sWorld.getChunkSource().blockChanged(this.worldPosition);
+ }
+ }
+
+ @Override
+ public void load(CompoundTag nbt) {
+ super.load(nbt);
+
+ this.frame = AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame")));
+ this.engine = AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine")));
+
+ var wheelNbt = nbt.getCompound("wheels");
+ this.wheel = AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(wheelNbt.getString("type")));
+ this.wheelCount = wheelNbt.getInt("count");
+
+ onComponentsUpdated();
+ }
+
+ @Override
+ protected void saveAdditional(CompoundTag nbt) {
+ super.saveAdditional(nbt);
+
+ nbt.putString("frame", this.frame.getId().toString());
+ nbt.putString("engine", this.engine.getId().toString());
+
+ var wheelNbt = new CompoundTag();
+ wheelNbt.putString("type", this.wheel.getId().toString());
+ wheelNbt.putInt("count", this.wheelCount);
+ nbt.put("wheels", wheelNbt);
+ }
+
+ @Nullable
+ @Override
+ public Packet getUpdatePacket() {
+ return ClientboundBlockEntityDataPacket.create(this);
+ }
+
+ @Override
+ public CompoundTag getUpdateTag() {
+ var nbt = new CompoundTag();
+ this.saveAdditional(nbt);
+ return nbt;
+ }
+
+ protected boolean powered() {
+ var state = this.level.getBlockState(this.worldPosition);
+ return state.hasProperty(AutomobileAssemblerBlock.POWERED) && state.getValue(AutomobileAssemblerBlock.POWERED);
+ }
+
+ @Override
+ public float getAutomobileYaw(float tickDelta) {
+ var state = this.level.getBlockState(this.worldPosition);
+ return state.hasProperty(AutomobileAssemblerBlock.FACING) ? (state.getValue(AutomobileAssemblerBlock.FACING).toYRot() - 90) : 0;
+ }
+
+ @Override
+ public int getWheelCount() {
+ return this.wheelCount;
+ }
+
+ @Override
+ public float getRearAttachmentYaw(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getWheelAngle(float tickDelta) {
+ return this.powered() ? (this.getTime() + tickDelta) * 36 : 0;
+ }
+
+ @Override
+ public float getSteering(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public float getSuspensionBounce(float tickDelta) {
+ return 0;
+ }
+
+ @Override
+ public boolean engineRunning() {
+ return this.powered();
+ }
+
+ @Override
+ public int getBoostTimer() {
+ return this.powered() ? 1 : 0;
+ }
+
+ @Override
+ public int getTurboCharge() {
+ return 0;
+ }
+
+ @Override
+ public long getTime() {
+ return this.level.getGameTime();
+ }
+
+ @Override
+ public boolean automobileOnGround() {
+ return false;
+ }
+
+ @Override
+ public boolean debris() {
+ return false;
+ }
+
+ @Override
+ public Vector3f debrisColor() {
+ return null;
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java
new file mode 100644
index 0000000..c7436b0
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/entity/render/AutomobileAssemblerBlockEntityRenderer.java
@@ -0,0 +1,43 @@
+package io.github.foundationgames.automobility.block.entity.render;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer;
+import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity;
+import net.minecraft.client.gui.Font;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
+import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+
+public class AutomobileAssemblerBlockEntityRenderer implements BlockEntityRenderer {
+ private final Font textRenderer;
+
+ public AutomobileAssemblerBlockEntityRenderer(BlockEntityRendererProvider.Context blockEntityCtx) {
+ this.textRenderer = blockEntityCtx.getFont();
+ }
+
+ @Override
+ public void render(AutomobileAssemblerBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
+ matrices.pushPose();
+ matrices.translate(0.5, 0.75 - (entity.getWheels().model().radius() / 16), 0.5);
+ AutomobileRenderer.render(matrices, vertexConsumers, light, overlay, tickDelta, entity);
+ matrices.popPose();
+
+ matrices.pushPose();
+ matrices.translate(0.5, 0, 0.5);
+ matrices.mulPose(Vector3f.YP.rotationDegrees(-entity.getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot()));
+ matrices.translate(0, 0.372, 0.501);
+ matrices.scale(0.008f, -0.008f, -0.008f);
+
+ for (var text : entity.label) {
+ matrices.pushPose();
+ matrices.translate(-0.5 * textRenderer.width(text), 0, 0);
+ textRenderer.drawShadow(matrices, text, 0, 0, 0xFFFFFF);
+ matrices.popPose();
+ matrices.translate(0, 12, 0);
+ }
+
+ matrices.popPose();
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java
new file mode 100644
index 0000000..9e91f99
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/GeometryBuilder.java
@@ -0,0 +1,13 @@
+package io.github.foundationgames.automobility.block.model;
+
+import net.minecraft.client.renderer.texture.TextureAtlasSprite;
+import net.minecraft.core.Direction;
+import org.jetbrains.annotations.Nullable;
+
+public interface GeometryBuilder {
+ GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz,
+ TextureAtlasSprite sprite, float u, float v);
+
+ GeometryBuilder vertex(float x, float y, float z, @Nullable Direction face, float nx, float ny, float nz,
+ TextureAtlasSprite sprite, float u, float v, int color);
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java
new file mode 100644
index 0000000..bc777bf
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeBakedModel.java
@@ -0,0 +1,247 @@
+package io.github.foundationgames.automobility.block.model;
+
+import com.mojang.math.Vector3f;
+import io.github.foundationgames.automobility.platform.Platform;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.block.model.BakedQuad;
+import net.minecraft.client.renderer.block.model.ItemOverrides;
+import net.minecraft.client.renderer.block.model.ItemTransforms;
+import net.minecraft.client.renderer.texture.TextureAtlasSprite;
+import net.minecraft.client.resources.model.BakedModel;
+import net.minecraft.client.resources.model.ModelState;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.util.RandomSource;
+import net.minecraft.world.level.BlockAndTintGetter;
+import net.minecraft.world.level.block.state.BlockState;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class SlopeBakedModel implements BakedModel {
+ public static Factory impl = SlopeBakedModel::new;
+
+ private final Map frameTexOverrides;
+
+ protected final @Nullable TextureAtlasSprite plateInner;
+ protected final @Nullable TextureAtlasSprite plateOuter;
+ protected final ModelState settings;
+ protected final SlopeUnbakedModel.Type type;
+ private final TextureAtlasSprite frame;
+
+ public SlopeBakedModel(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner,
+ @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type) {
+ this.frame = frame;
+ this.frameTexOverrides = frameTexOverrides;
+ this.plateInner = plateInner;
+ this.plateOuter = plateOuter;
+ this.settings = settings;
+ this.type = type;
+ }
+
+ public TextureAtlasSprite getFrameSprite(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos) {
+ if (level != null && pos != null) {
+ var blockBelow = level.getBlockState(pos.below());
+
+ if (frameTexOverrides.containsKey(blockBelow)) {
+ return frameTexOverrides.get(blockBelow);
+ }
+ if (!blockBelow.isAir() && blockBelow.isCollisionShapeFullBlock(level, pos)) {
+ return Minecraft.getInstance().getBlockRenderer().getBlockModel(blockBelow).getParticleIcon();
+ }
+ }
+
+ return this.frame;
+ }
+
+ public int getFrameColor(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos) {
+ if (level != null && pos != null) {
+ var blockBelow = level.getBlockState(pos.below());
+ var belowColor = Platform.get().blockColor(blockBelow);
+
+ if (belowColor != null) {
+ return belowColor.getColor(blockBelow, level, pos.below(), 0) | 0xFF000000;
+ }
+ }
+
+ return 0xFFFFFFFF;
+ }
+
+ public void buildSlopeGeometry(TextureAtlasSprite sprite, GeometryBuilder geo, int frameColor, boolean borderedLeft, boolean borderedRight) {
+ boolean steep = type == SlopeUnbakedModel.Type.STEEP;
+ float height = steep ? 1 : 0.5f;
+ float rise = steep ? 0 : (type == SlopeUnbakedModel.Type.TOP ? 0.5f : 0);
+ boolean top = true;
+
+ if (this.plateOuter != null && this.plateInner != null) {
+ top = false;
+ this.plate(height, rise, !borderedLeft, !borderedRight, this.plateInner, this.plateOuter, geo);
+ }
+
+ rightTriPrism(height, rise, frameColor, top, sprite, geo);
+
+ float invRH = 1 - (rise + height);
+ geo
+ // South face
+ .vertex(0, rise + height, 1, Direction.SOUTH, 0, 0, 1, sprite, 0, invRH, frameColor)
+ .vertex(0, 0, 1, Direction.SOUTH, 0, 0, 1, sprite, 0, 1, frameColor)
+ .vertex(1, 0, 1, Direction.SOUTH, 0, 0, 1, sprite, 1, 1, frameColor)
+ .vertex(1, rise + height, 1, Direction.SOUTH, 0, 0, 1, sprite, 1, invRH, frameColor)
+
+ // Bottom face
+ .vertex(0, 0, 1, Direction.DOWN, 0, -1, 0, sprite, 0, 0, frameColor)
+ .vertex(0, 0, 0, Direction.DOWN, 0, -1, 0, sprite, 0, 1, frameColor)
+ .vertex(1, 0, 0, Direction.DOWN, 0, -1, 0, sprite, 1, 1, frameColor)
+ .vertex(1, 0, 1, Direction.DOWN, 0, -1, 0, sprite, 1, 0, frameColor);
+
+ if (rise > 0) {
+ float invR = 1 - rise;
+ geo
+ // West face
+ .vertex(0, rise, 0, Direction.WEST, -1, 0, 0, sprite, 0, invR, frameColor)
+ .vertex(0, 0, 0, Direction.WEST, -1, 0, 0, sprite, 0, 1, frameColor)
+ .vertex(0, 0, 1, Direction.WEST, -1, 0, 0, sprite, 1, 1, frameColor)
+ .vertex(0, rise, 1, Direction.WEST, -1, 0, 0, sprite, 1, invR, frameColor)
+
+ // East face
+ .vertex(1, rise, 1, Direction.EAST, 1, 0, 0, sprite, 1, invR, frameColor)
+ .vertex(1, 0, 1, Direction.EAST, 1, 0, 0, sprite, 1, 1, frameColor)
+ .vertex(1, 0, 0, Direction.EAST, 1, 0, 0, sprite, 0, 1, frameColor)
+ .vertex(1, rise, 0, Direction.EAST, 1, 0, 0, sprite, 0, invR, frameColor)
+
+ // North face
+ .vertex(1, rise, 0, Direction.NORTH, 0, 0, 1, sprite, 1, invR, frameColor)
+ .vertex(1, 0, 0, Direction.NORTH, 0, 0, 1, sprite, 1, 1, frameColor)
+ .vertex(0, 0, 0, Direction.NORTH, 0, 0, 1, sprite, 0, 1, frameColor)
+ .vertex(0, rise, 0, Direction.NORTH, 0, 0, 1, sprite, 0, invR, frameColor);
+ }
+ }
+
+ private void rightTriPrism(float height, float rise, int color, boolean top, TextureAtlasSprite sprite, GeometryBuilder geo) {
+ float invR = 1 - rise;
+ float invRH = 1 - (rise + height);
+ var topNormal = new Vector3f(0, 1, -height); // This actually makes sense math wise don't worry about it
+ topNormal.normalize();
+
+ geo
+ // West triangle
+ .vertex(0, rise + height, 1, Direction.WEST, -1, 0, 0, sprite, 1, invRH, color)
+ .vertex(0, rise, 0, Direction.WEST, -1, 0, 0, sprite, 0, invR, color)
+ .vertex(0, rise, 1, Direction.WEST, -1, 0, 0, sprite, 1, invR, color)
+ .vertex(0, rise + height, 1, Direction.WEST, -1, 0, 0, sprite, 1, invRH, color)
+
+ // East triangle
+ .vertex(1, rise + height, 1, Direction.EAST, 1, 0, 0, sprite, 0, invRH, color)
+ .vertex(1, rise + height, 1, Direction.EAST, 1, 0, 0, sprite, 0, invRH, color)
+ .vertex(1, rise, 1, Direction.EAST, 1, 0, 0, sprite, 0, invR, color)
+ .vertex(1, rise, 0, Direction.EAST, 1, 0, 0, sprite, 1, invR, color);
+
+ if (top) {
+ geo // Top face
+ .vertex(0, rise, 0, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 1, 1, color)
+ .vertex(0, rise + height, 1, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 1, 0, color)
+ .vertex(1, rise + height, 1, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 0, 0, color)
+ .vertex(1, rise, 0, null, topNormal.x(), topNormal.y(), topNormal.z(), sprite, 0, 1, color);
+ }
+ }
+
+ private void plate(float height, float rise, boolean left, boolean right, TextureAtlasSprite plateInner, TextureAtlasSprite plateOuter, GeometryBuilder geo) {
+ var topNormal = new Vector3f(0, 1, -height);
+ topNormal.normalize();
+ var northNormal = new Vector3f(0, -height, 1);
+ northNormal.normalize();
+ var southNormal = new Vector3f(0, height, 1);
+ southNormal.normalize();
+
+ var topFaceOffset = topNormal.copy(); // Translate from the surface of the slope to the surface of the plate
+ topFaceOffset.mul(0.0625f);
+ var onePxUp = southNormal.copy(); // Translate one pixel up the slope
+ onePxUp.normalize();
+ onePxUp.mul(0.0625f);
+
+ geo
+ // Top face inner
+ .vertex(right ? 0.9375f : 1, 0.001f + rise + topFaceOffset.y() + onePxUp.y(), topFaceOffset.z() + onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, right ? 0.0625f : 0, 0.9375f)
+ .vertex(left ? 0.0625f : 0, 0.001f + rise + topFaceOffset.y() + onePxUp.y(), topFaceOffset.z() + onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, left ? 0.9375f : 1, 0.9375f)
+ .vertex(left ? 0.0625f : 0, (0.001f + rise + height + topFaceOffset.y()) - onePxUp.y(), (1 + topFaceOffset.z()) - onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, left ? 0.9375f : 1, 0.0625f)
+ .vertex(right ? 0.9375f : 1, (0.001f + rise + height + topFaceOffset.y()) - onePxUp.y(), (1 + topFaceOffset.z()) - onePxUp.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateInner, right ? 0.0625f : 0, 0.0625f)
+
+ // Top face outer
+ .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 0, 1)
+ .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 1, 1)
+ .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 1, 0)
+ .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, topNormal.x(), topNormal.y(), topNormal.z(), plateOuter, 0, 0)
+
+ // North face
+ .vertex(1, rise, 0, null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 0, 1)
+ .vertex(0, rise, 0, null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 1, 1)
+ .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 1, 0.9375f)
+ .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, northNormal.x(), northNormal.y(), northNormal.z(), plateOuter, 0, 0.9375f)
+
+ // South face
+ .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 0, 0)
+ .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 1, 0)
+ .vertex(0, rise + height, 1, null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 1, 0.0625f)
+ .vertex(1, rise + height, 1, null, southNormal.x(), southNormal.y(), southNormal.z(), plateOuter, 0, 0.0625f)
+
+ // East face
+ .vertex(1, rise + height, 1, null, 1, 0, 0, plateOuter, 0, 0)
+ .vertex(1, rise, 0, null, 1, 0, 0, plateOuter, 0, 1)
+ .vertex(1, rise + topFaceOffset.y(), topFaceOffset.z(), null, 1, 0, 0, plateOuter, 0.0625f, 1)
+ .vertex(1, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, 1, 0, 0, plateOuter, 0.0625f, 0)
+
+ // West face
+ .vertex(0, rise + height + topFaceOffset.y(), 1 + topFaceOffset.z(), null, -1, 0, 0, plateOuter, 1, 0)
+ .vertex(0, rise + topFaceOffset.y(), topFaceOffset.z(), null, -1, 0, 0, plateOuter, 1, 1)
+ .vertex(0, rise, 0, null, -1, 0, 0, plateOuter, 0.9375f, 1)
+ .vertex(0, rise + height, 1, null, -1, 0, 0, plateOuter, 0.9375f, 0)
+ ;
+ }
+
+ @Override
+ public List getQuads(@Nullable BlockState blockState, @Nullable Direction direction, RandomSource randomSource) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean useAmbientOcclusion() {
+ return true;
+ }
+
+ @Override
+ public boolean isGui3d() {
+ return true;
+ }
+
+ @Override
+ public boolean usesBlockLight() {
+ return true;
+ }
+
+ @Override
+ public boolean isCustomRenderer() {
+ return false;
+ }
+
+ @Override
+ public TextureAtlasSprite getParticleIcon() {
+ return this.getFrameSprite(null, null);
+ }
+
+ @Override
+ public ItemTransforms getTransforms() {
+ return ItemTransforms.NO_TRANSFORMS;
+ }
+
+ @Override
+ public ItemOverrides getOverrides() {
+ return ItemOverrides.EMPTY;
+ }
+
+ public interface Factory {
+ SlopeBakedModel create(TextureAtlasSprite frame, Map frameTexOverrides, @Nullable TextureAtlasSprite plateInner,
+ @Nullable TextureAtlasSprite plateOuter, ModelState settings, SlopeUnbakedModel.Type type);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java
new file mode 100644
index 0000000..2781bb1
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/block/model/SlopeUnbakedModel.java
@@ -0,0 +1,113 @@
+package io.github.foundationgames.automobility.block.model;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.mojang.datafixers.util.Pair;
+import io.github.foundationgames.automobility.Automobility;
+import net.minecraft.client.renderer.texture.TextureAtlas;
+import net.minecraft.client.renderer.texture.TextureAtlasSprite;
+import net.minecraft.client.resources.model.BakedModel;
+import net.minecraft.client.resources.model.Material;
+import net.minecraft.client.resources.model.ModelBakery;
+import net.minecraft.client.resources.model.ModelState;
+import net.minecraft.client.resources.model.UnbakedModel;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.state.BlockState;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class SlopeUnbakedModel implements UnbakedModel {
+ public static final ResourceLocation MODEL_SLOPE_BOTTOM = Automobility.rl("block/slope_bottom");
+ public static final ResourceLocation MODEL_SLOPE_TOP = Automobility.rl("block/slope_top");
+ public static final ResourceLocation MODEL_STEEP_SLOPE = Automobility.rl("block/steep_slope");
+ public static final ResourceLocation MODEL_SLOPE_BOTTOM_DASH_PANEL = Automobility.rl("block/slope_bottom_dash_panel");
+ public static final ResourceLocation MODEL_SLOPE_TOP_DASH_PANEL = Automobility.rl("block/slope_top_dash_panel");
+ public static final ResourceLocation MODEL_STEEP_SLOPE_DASH_PANEL = Automobility.rl("block/steep_slope_dash_panel");
+ public static final ResourceLocation MODEL_SLOPE_BOTTOM_DASH_PANEL_OFF = Automobility.rl("block/slope_bottom_dash_panel_off");
+ public static final ResourceLocation MODEL_SLOPE_TOP_DASH_PANEL_OFF = Automobility.rl("block/slope_top_dash_panel_off");
+ public static final ResourceLocation MODEL_STEEP_SLOPE_DASH_PANEL_OFF = Automobility.rl("block/steep_slope_dash_panel_off");
+
+ public static final ResourceLocation TEX_FRAME = Automobility.rl("block/slope_frame");
+ public static final ResourceLocation TEX_DASH_PANEL = Automobility.rl("block/dash_panel");
+ public static final ResourceLocation TEX_DASH_PANEL_OFF = Automobility.rl("block/dash_panel_off");
+ public static final ResourceLocation TEX_DASH_PANEL_FRAME = Automobility.rl("block/dash_panel_frame");
+
+ public static final Map> DEFAULT_MODELS = ImmutableMap.of(
+ MODEL_SLOPE_TOP, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, null, null),
+ MODEL_SLOPE_BOTTOM, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, null, null),
+ MODEL_STEEP_SLOPE, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, null, null),
+ MODEL_SLOPE_TOP_DASH_PANEL, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME),
+ MODEL_SLOPE_BOTTOM_DASH_PANEL, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME),
+ MODEL_STEEP_SLOPE_DASH_PANEL, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, TEX_DASH_PANEL, TEX_DASH_PANEL_FRAME),
+ MODEL_SLOPE_TOP_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.TOP, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME),
+ MODEL_SLOPE_BOTTOM_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.BOTTOM, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME),
+ MODEL_STEEP_SLOPE_DASH_PANEL_OFF, () -> new SlopeUnbakedModel(Type.STEEP, TEX_FRAME, TEX_DASH_PANEL_OFF, TEX_DASH_PANEL_FRAME)
+ );
+
+ private static final ResourceLocation PARENT = new ResourceLocation("block/block");
+
+ private final Type type;
+ private final Material frameTex;
+ private final @Nullable Material plateInnerTex;
+ private final @Nullable Material plateOuterTex;
+
+ public SlopeUnbakedModel(Type type, ResourceLocation frameTex, @Nullable ResourceLocation plateInnerTex,
+ @Nullable ResourceLocation plateOuterTex) {
+ this.type = type;
+ this.frameTex = new Material(TextureAtlas.LOCATION_BLOCKS, frameTex);
+ this.plateInnerTex = plateInnerTex != null ? new Material(TextureAtlas.LOCATION_BLOCKS, plateInnerTex) : null;
+ this.plateOuterTex = plateOuterTex != null ? new Material(TextureAtlas.LOCATION_BLOCKS, plateOuterTex) : null;
+ }
+
+ @Override
+ public Collection getDependencies() {
+ return List.of(PARENT);
+ }
+
+ @Override
+ public Collection getMaterials(Function function, Set> set) {
+ var list = Lists.newArrayList(this.frameTex);
+ if (this.plateInnerTex != null) {
+ list.add(this.plateInnerTex);
+ }
+ if (this.plateOuterTex != null) {
+ list.add(this.plateOuterTex);
+ }
+
+ return list;
+ }
+
+ // TODO: Something better than this that supports other mods and resource packs
+ private static Map createFrameTexOverrides(Function spriteGet) {
+ return ImmutableMap.of(
+ Blocks.GRASS_BLOCK.defaultBlockState(), vanillaSprite(spriteGet, "block/grass_block_top"),
+ Blocks.PODZOL.defaultBlockState(), vanillaSprite(spriteGet, "block/podzol_top"),
+ Blocks.MYCELIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/mycelium_top"),
+ Blocks.CRIMSON_NYLIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/crimson_nylium"),
+ Blocks.WARPED_NYLIUM.defaultBlockState(), vanillaSprite(spriteGet, "block/warped_nylium")
+ );
+ }
+
+ @Nullable
+ @Override
+ public BakedModel bake(ModelBakery modelBakery, Function function, ModelState modelState, ResourceLocation resourceLocation) {
+ return SlopeBakedModel.impl.create(function.apply(frameTex), createFrameTexOverrides(function),
+ plateInnerTex != null ? function.apply(plateInnerTex) : null,
+ plateOuterTex != null ? function.apply(plateOuterTex) : null, modelState, type);
+ }
+
+ private static TextureAtlasSprite vanillaSprite(Function spriteGet, String name) {
+ return spriteGet.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation("minecraft", name)));
+ }
+
+ public enum Type {
+ BOTTOM, TOP, STEEP
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java
similarity index 78%
rename from src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java
rename to common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java
index 2ffde65..bf38b17 100644
--- a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileDamageSource.java
@@ -1,6 +1,6 @@
package io.github.foundationgames.automobility.entity;
-import net.minecraft.entity.damage.DamageSource;
+import net.minecraft.world.damagesource.DamageSource;
public class AutomobileDamageSource extends DamageSource {
protected AutomobileDamageSource(String name) {
diff --git a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java
similarity index 65%
rename from src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java
rename to common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java
index ec32f94..8443551 100644
--- a/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java
@@ -1,5 +1,6 @@
package io.github.foundationgames.automobility.entity;
+import com.mojang.math.Vector3f;
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.AutomobileEngine;
import io.github.foundationgames.automobility.automobile.AutomobileFrame;
@@ -12,61 +13,55 @@
import io.github.foundationgames.automobility.automobile.attachment.rear.DeployableRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
import io.github.foundationgames.automobility.automobile.render.RenderableAutomobile;
-import io.github.foundationgames.automobility.screen.AutomobileScreenHandlerContext;
import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock;
import io.github.foundationgames.automobility.block.LaunchGelBlock;
import io.github.foundationgames.automobility.block.OffRoadBlock;
import io.github.foundationgames.automobility.item.AutomobileInteractable;
import io.github.foundationgames.automobility.item.AutomobilityItems;
import io.github.foundationgames.automobility.particle.AutomobilityParticles;
-import io.github.foundationgames.automobility.sound.AutomobileSoundInstance;
+import io.github.foundationgames.automobility.platform.Platform;
+import io.github.foundationgames.automobility.screen.AutomobileContainerLevelAccess;
import io.github.foundationgames.automobility.sound.AutomobilitySounds;
import io.github.foundationgames.automobility.util.AUtils;
import io.github.foundationgames.automobility.util.duck.CollisionArea;
-import io.github.foundationgames.automobility.util.midnightcontrols.ControllerUtils;
-import io.github.foundationgames.automobility.util.network.PayloadPackets;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.block.ShapeContext;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.model.Model;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityType;
-import net.minecraft.entity.ItemEntity;
-import net.minecraft.entity.LivingEntity;
-import net.minecraft.entity.MovementType;
-import net.minecraft.entity.damage.DamageSource;
-import net.minecraft.entity.data.DataTracker;
-import net.minecraft.entity.data.TrackedData;
-import net.minecraft.entity.data.TrackedDataHandlerRegistry;
-import net.minecraft.entity.mob.MobEntity;
-import net.minecraft.entity.mob.WaterCreatureEntity;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.entity.vehicle.BoatEntity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.network.Packet;
-import net.minecraft.network.PacketByteBuf;
-import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
-import net.minecraft.predicate.entity.EntityPredicates;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.sound.SoundCategory;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.util.ActionResult;
-import net.minecraft.util.CuboidBlockIterator;
-import net.minecraft.util.Hand;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.TypeFilter;
-import net.minecraft.util.function.BooleanBiFunction;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Box;
-import net.minecraft.util.math.MathHelper;
-import net.minecraft.util.math.Vec3d;
-import net.minecraft.util.math.Vec3f;
-import net.minecraft.util.shape.VoxelShapes;
-import net.minecraft.world.World;
-import net.minecraft.world.event.GameEvent;
+import io.github.foundationgames.automobility.util.network.ClientPackets;
+import io.github.foundationgames.automobility.util.network.CommonPackets;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Cursor3D;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.protocol.Packet;
+import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
+import net.minecraft.network.syncher.EntityDataAccessor;
+import net.minecraft.network.syncher.EntityDataSerializers;
+import net.minecraft.network.syncher.SynchedEntityData;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.util.Mth;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.damagesource.DamageSource;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntitySelector;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.entity.Mob;
+import net.minecraft.world.entity.MoverType;
+import net.minecraft.world.entity.animal.WaterAnimal;
+import net.minecraft.world.entity.item.ItemEntity;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.entity.vehicle.Boat;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.entity.EntityTypeTest;
+import net.minecraft.world.level.gameevent.GameEvent;
+import net.minecraft.world.phys.AABB;
+import net.minecraft.world.phys.Vec3;
+import net.minecraft.world.phys.shapes.BooleanOp;
+import net.minecraft.world.phys.shapes.CollisionContext;
+import net.minecraft.world.phys.shapes.Shapes;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
@@ -79,9 +74,12 @@
import java.util.function.Consumer;
public class AutomobileEntity extends Entity implements RenderableAutomobile, EntityWithInventory {
- private static final TrackedData REAR_ATTACHMENT_YAW = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT);
- private static final TrackedData REAR_ATTACHMENT_ANIMATION = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT);
- private static final TrackedData FRONT_ATTACHMENT_ANIMATION = DataTracker.registerData(AutomobileEntity.class, TrackedDataHandlerRegistry.FLOAT);
+ public static Consumer engineSound = e -> {};
+ public static Consumer skidSound = e -> {};
+
+ private static final EntityDataAccessor REAR_ATTACHMENT_YAW = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT);
+ private static final EntityDataAccessor REAR_ATTACHMENT_ANIMATION = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT);
+ private static final EntityDataAccessor FRONT_ATTACHMENT_ANIMATION = SynchedEntityData.defineId(AutomobileEntity.class, EntityDataSerializers.FLOAT);
private AutomobileFrame frame = AutomobileFrame.REGISTRY.getOrDefault(null);
private AutomobileWheel wheels = AutomobileWheel.REGISTRY.getOrDefault(null);
@@ -91,17 +89,6 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En
private final AutomobileStats stats = new AutomobileStats();
- @Environment(EnvType.CLIENT)
- private Model frameModel = null;
- @Environment(EnvType.CLIENT)
- private Model wheelModel = null;
- @Environment(EnvType.CLIENT)
- private Model engineModel = null;
- @Environment(EnvType.CLIENT)
- private @Nullable Model rearAttachmentModel = null;
- @Environment(EnvType.CLIENT)
- private @Nullable Model frontAttachmentModel = null;
-
public static final int SMALL_TURBO_TIME = 35;
public static final int MEDIUM_TURBO_TIME = 70;
public static final int LARGE_TURBO_TIME = 115;
@@ -129,7 +116,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En
private float hSpeed = 0;
private float vSpeed = 0;
- private Vec3d addedVelocity = getVelocity();
+ private Vec3 addedVelocity = getDeltaMovement();
private float steering = 0;
private float lastSteering = steering;
@@ -153,10 +140,10 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En
private boolean isFloorDirectlyBelow = true;
private boolean touchingWall = false;
- private Vec3d lastVelocity = Vec3d.ZERO;
- private Vec3d lastPosForDisplacement = Vec3d.ZERO;
+ private Vec3 lastVelocity = Vec3.ZERO;
+ private Vec3 lastPosForDisplacement = Vec3.ZERO;
- private Vec3d prevTailPos = null;
+ private Vec3 prevTailPos = null;
private int slopeStickingTimer = 0;
private float grip = 1;
@@ -167,7 +154,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En
private final Deque prevYDisplacements = new ArrayDeque<>();
private boolean offRoad = false;
- private Vec3f debrisColor = new Vec3f();
+ private Vector3f debrisColor = new Vector3f();
private int fallTicks = 0;
@@ -179,7 +166,7 @@ public class AutomobileEntity extends Entity implements RenderableAutomobile, En
private float standStillTime = -1.3f;
- public void writeSyncToClientData(PacketByteBuf buf) {
+ public void writeSyncToClientData(FriendlyByteBuf buf) {
buf.writeInt(boostTimer);
buf.writeFloat(steering);
buf.writeFloat(wheelAngle);
@@ -192,7 +179,7 @@ public void writeSyncToClientData(PacketByteBuf buf) {
buf.writeBoolean(burningOut);
}
- public void readSyncToClientData(PacketByteBuf buf) {
+ public void readSyncToClientData(FriendlyByteBuf buf) {
boostTimer = buf.readInt();
steering = buf.readFloat();
wheelAngle = buf.readFloat();
@@ -206,11 +193,11 @@ public void readSyncToClientData(PacketByteBuf buf) {
}
@Override
- public void readCustomDataFromNbt(NbtCompound nbt) {
+ public void readAdditionalSaveData(CompoundTag nbt) {
setComponents(
- AutomobileFrame.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("frame"))),
- AutomobileWheel.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("wheels"))),
- AutomobileEngine.REGISTRY.getOrDefault(Identifier.tryParse(nbt.getString("engine")))
+ AutomobileFrame.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("frame"))),
+ AutomobileWheel.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("wheels"))),
+ AutomobileEngine.REGISTRY.getOrDefault(ResourceLocation.tryParse(nbt.getString("engine")))
);
var rAtt = nbt.getCompound("rearAttachment");
@@ -246,12 +233,10 @@ public void readCustomDataFromNbt(NbtCompound nbt) {
despawnTime = nbt.getInt("despawnTime");
despawnCountdown = nbt.getInt("despawnCountdown");
decorative = nbt.getBoolean("decorative");
-
- updateModels = true;
}
@Override
- public void writeCustomDataToNbt(NbtCompound nbt) {
+ public void addAdditionalSaveData(CompoundTag nbt) {
nbt.putString("frame", frame.getId().toString());
nbt.putString("wheels", wheels.getId().toString());
nbt.putString("engine", engine.getId().toString());
@@ -310,25 +295,22 @@ public void readCompactedInputData(byte data) {
accelerating = (1 & d) > 0;
}
- @Environment(EnvType.CLIENT)
- public boolean updateModels = true;
-
- public AutomobileEntity(EntityType> type, World world) {
+ public AutomobileEntity(EntityType> type, Level world) {
super(type, world);
this.setRearAttachment(RearAttachmentType.REGISTRY.getOrDefault(null));
this.setFrontAttachment(FrontAttachmentType.REGISTRY.getOrDefault(null));
}
- public AutomobileEntity(World world) {
- this(AutomobilityEntities.AUTOMOBILE, world);
+ public AutomobileEntity(Level world) {
+ this(AutomobilityEntities.AUTOMOBILE.require(), world);
}
@Override
- public void onSpawnPacket(EntitySpawnS2CPacket packet) {
- super.onSpawnPacket(packet);
- if (world.isClient()) {
- PayloadPackets.requestSyncAutomobileComponentsPacket(this);
+ public void recreateFromPacket(ClientboundAddEntityPacket packet) {
+ super.recreateFromPacket(packet);
+ if (level.isClientSide()) {
+ ClientPackets.requestSyncAutomobileComponentsPacket(this);
}
}
@@ -359,26 +341,26 @@ public AutomobileEngine getEngine() {
@Override
public float getSteering(float tickDelta) {
- return MathHelper.lerp(tickDelta, lastSteering, steering);
+ return Mth.lerp(tickDelta, lastSteering, steering);
}
@Override
public float getWheelAngle(float tickDelta) {
- return MathHelper.lerp(tickDelta, lastWheelAngle, wheelAngle);
+ return Mth.lerp(tickDelta, lastWheelAngle, wheelAngle);
}
public float getBoostSpeed(float tickDelta) {
- return MathHelper.lerp(tickDelta, lastBoostSpeed, boostSpeed);
+ return Mth.lerp(tickDelta, lastBoostSpeed, boostSpeed);
}
@Override
public float getSuspensionBounce(float tickDelta) {
- return MathHelper.lerp(tickDelta, lastSusBounceTimer, suspensionBounceTimer);
+ return Mth.lerp(tickDelta, lastSusBounceTimer, suspensionBounceTimer);
}
@Override
public boolean engineRunning() {
- return hasPassengers();
+ return this.boostTimer > 0 || isVehicle();
}
@Override
@@ -405,7 +387,7 @@ public int getBoostTimer() {
}
public double getEffectiveSpeed() {
- if (this.getPrimaryPassenger() instanceof PlayerEntity player && player.isMainPlayer()) {
+ if (this.getControllingPassenger() instanceof Player player && player.isLocalPlayer()) {
return Math.max(this.addedVelocity.length(), Math.abs(this.hSpeed));
}
@@ -423,7 +405,7 @@ public boolean debris() {
}
@Override
- public Vec3f debrisColor() {
+ public Vector3f debrisColor() {
return debrisColor;
}
@@ -432,16 +414,16 @@ public boolean burningOut() {
}
private void setDrifting(boolean drifting) {
- if (this.world.isClient() && !this.drifting && drifting) {
- playSkiddingSound();
+ if (this.level.isClientSide() && !this.drifting && drifting) {
+ skidSound.accept(this);
}
this.drifting = drifting;
}
private void setBurningOut(boolean burningOut) {
- if (this.world.isClient() && !this.drifting && !this.burningOut && burningOut) {
- playSkiddingSound();
+ if (this.level.isClientSide() && !this.drifting && !this.burningOut && burningOut) {
+ skidSound.accept(this);
}
this.burningOut = burningOut;
@@ -461,13 +443,12 @@ public void setRearAttachment(RearAttachmentType r
}
this.rearAttachment = rearAttachment.constructor().apply(rearAttachment, this);
- this.rearAttachment.setYaw(this.getYaw());
+ this.rearAttachment.setYaw(this.getYRot());
- if (!world.isClient() && !this.rearAttachment.isRideable() && this.getPassengerList().size() > 1) {
- this.getPassengerList().get(1).stopRiding();
+ if (!level.isClientSide() && !this.rearAttachment.isRideable() && this.getPassengers().size() > 1) {
+ this.getPassengers().get(1).stopRiding();
}
- this.updateModels = true;
syncAttachments();
}
}
@@ -482,7 +463,6 @@ public void setFrontAttachment(FrontAttachmentType action) {
- for (PlayerEntity p : world.getPlayers()) {
+ public void forNearbyPlayers(int radius, boolean ignoreDriver, Consumer action) {
+ for (Player p : level.players()) {
if (ignoreDriver && p == getFirstPassenger()) {
continue;
}
- if (p.getPos().distanceTo(getPos()) < radius && p instanceof ServerPlayerEntity player) {
+ if (p.position().distanceTo(position()) < radius && p instanceof ServerPlayer player) {
action.accept(player);
}
}
}
- public Vec3d getTailPos() {
- return this.getPos()
- .add(new Vec3d(0, 0, this.getFrame().model().rearAttachmentPos() * 0.0625)
- .rotateY((float) Math.toRadians(180 - this.getYaw()))
+ public Vec3 getTailPos() {
+ return this.position()
+ .add(new Vec3(0, 0, this.getFrame().model().rearAttachmentPos() * 0.0625)
+ .yRot((float) Math.toRadians(180 - this.getYRot()))
);
}
- public Vec3d getHeadPos() {
- return this.getPos()
- .add(new Vec3d(0, 0, this.getFrame().model().frontAttachmentPos() * 0.0625)
- .rotateY((float) Math.toRadians(-this.getYaw()))
+ public Vec3 getHeadPos() {
+ return this.position()
+ .add(new Vec3(0, 0, this.getFrame().model().frontAttachmentPos() * 0.0625)
+ .yRot((float) Math.toRadians(-this.getYRot()))
);
}
public boolean hasSpaceForPassengers() {
- return (this.rearAttachment.isRideable()) ? (this.getPassengerList().size() < 2) : (!this.hasPassengers());
+ return (this.rearAttachment.isRideable()) ? (this.getPassengers().size() < 2) : (!this.isVehicle());
}
public void setSpeed(float horizontal, float vertical) {
@@ -532,35 +511,19 @@ public void setSpeed(float horizontal, float vertical) {
this.vSpeed = vertical;
}
- @Environment(EnvType.CLIENT)
- private void playEngineSound() {
- if (this.getEngine().isEmpty()) {
- return;
- }
-
- var client = MinecraftClient.getInstance();
- client.getSoundManager().play(new AutomobileSoundInstance.EngineSound(client, this));
- }
-
- @Environment(EnvType.CLIENT)
- private void playSkiddingSound() {
- var client = MinecraftClient.getInstance();
- client.getSoundManager().play(new AutomobileSoundInstance.SkiddingSound(client, this));
- }
-
@Override
public void tick() {
- boolean first = this.firstUpdate;
+ boolean first = this.firstTick;
if (lastWheelAngle != wheelAngle) markDirty();
lastWheelAngle = wheelAngle;
- if (!this.wasEngineRunning && this.engineRunning() && this.world.isClient()) {
- playEngineSound();
+ if (!this.wasEngineRunning && this.engineRunning() && this.level.isClientSide()) {
+ engineSound.accept(this);
}
this.wasEngineRunning = this.engineRunning();
- if (!this.hasPassengers() || !this.getFrontAttachment().canDrive(this.getFirstPassenger())) {
+ if (!this.isVehicle() || !this.getFrontAttachment().canDrive(this.getFirstPassenger())) {
accelerating = false;
braking = false;
steeringLeft = false;
@@ -576,7 +539,7 @@ public void tick() {
if (!this.rearAttachment.type.isEmpty()) this.rearAttachment.tick();
if (!this.frontAttachment.type.isEmpty()) this.frontAttachment.tick();
- var prevPos = this.getPos();
+ var prevPos = this.position();
positionTrackingTick();
collisionStateTick();
@@ -585,12 +548,12 @@ public void tick() {
burnoutTick();
movementTick();
- if (this.isLogicalSideForUpdatingMovement()) {
- this.move(MovementType.SELF, this.getVelocity());
+ if (this.isControlledByLocalInstance()) {
+ this.move(MoverType.SELF, this.getDeltaMovement());
}
postMovementTick();
- if (!world.isClient()) {
+ if (!level.isClientSide()) {
var prevTailPos = this.prevTailPos != null ? this.prevTailPos : this.getTailPos();
var tailPos = this.getTailPos();
@@ -602,17 +565,17 @@ public void tick() {
dirty = false;
}
if (this.hasSpaceForPassengers() && !decorative) {
- var touchingEntities = this.world.getOtherEntities(this, this.getBoundingBox().expand(0.2, 0, 0.2), EntityPredicates.canBePushedBy(this));
+ var touchingEntities = this.level.getEntities(this, this.getBoundingBox().inflate(0.2, 0, 0.2), EntitySelector.pushableBy(this));
for (Entity entity : touchingEntities) {
if (!entity.hasPassenger(this)) {
- if (!entity.hasVehicle() && entity.getWidth() <= this.getWidth() && entity instanceof MobEntity && !(entity instanceof WaterCreatureEntity)) {
+ if (!entity.isPassenger() && entity.getBbWidth() <= this.getBbWidth() && entity instanceof Mob && !(entity instanceof WaterAnimal)) {
entity.startRiding(this);
}
}
}
}
- if (this.hasPassengers()) {
- if (this.getFrontAttachment().canDrive(this.getFirstPassenger()) && this.getFirstPassenger() instanceof MobEntity mob) {
+ if (this.isVehicle()) {
+ if (this.getFrontAttachment().canDrive(this.getFirstPassenger()) && this.getFirstPassenger() instanceof Mob mob) {
provideMobDriverInputs(mob);
}
@@ -632,27 +595,27 @@ public void tick() {
suspensionBounceTimer--;
}
- if (Math.abs(this.hSpeed) < 0.05 && !this.burningOut && this.getPrimaryPassenger() instanceof PlayerEntity) {
+ if (Math.abs(this.hSpeed) < 0.05 && !this.burningOut && this.getControllingPassenger() instanceof Player) {
this.standStillTime = AUtils.shift(this.standStillTime, 0.05f, 1f);
} else {
this.standStillTime = AUtils.shift(this.standStillTime, 0.15f, -1.3f);
}
}
- displacementTick(first || (this.getPos().subtract(prevPos).length() > 0 || this.getYaw() != this.prevYaw));
+ displacementTick(first || (this.position().subtract(prevPos).length() > 0 || this.getYRot() != this.yRotO));
}
public void positionTrackingTick() {
- if (this.isLogicalSideForUpdatingMovement()) {
+ if (this.isControlledByLocalInstance()) {
this.lerpTicks = 0;
- updateTrackedPosition(getX(), getY(), getZ());
+ syncPacketPositionCodec(getX(), getY(), getZ());
} else if (lerpTicks > 0) {
- this.setPosition(
+ this.setPos(
this.getX() + ((this.trackedX - this.getX()) / (double)this.lerpTicks),
this.getY() + ((this.trackedY - this.getY()) / (double)this.lerpTicks),
this.getZ() + ((this.trackedZ - this.getZ()) / (double)this.lerpTicks)
);
- this.setYaw(this.getYaw() + (MathHelper.wrapDegrees(this.trackedYaw - this.getYaw()) / (float)this.lerpTicks));
+ this.setYRot(this.getYRot() + (Mth.wrapDegrees(this.trackedYaw - this.getYRot()) / (float)this.lerpTicks));
this.lerpTicks--;
}
@@ -663,20 +626,20 @@ public void markDirty() {
}
private void syncData() {
- forNearbyPlayers(200, true, player -> PayloadPackets.sendSyncAutomobileDataPacket(this, player));
+ forNearbyPlayers(200, true, player -> CommonPackets.sendSyncAutomobileDataPacket(this, player));
}
private void syncComponents() {
- forNearbyPlayers(200, false, player -> PayloadPackets.sendSyncAutomobileComponentsPacket(this, player));
+ forNearbyPlayers(200, false, player -> CommonPackets.sendSyncAutomobileComponentsPacket(this, player));
}
private void syncAttachments() {
- forNearbyPlayers(200, false, player -> PayloadPackets.sendSyncAutomobileAttachmentsPacket(this, player));
+ forNearbyPlayers(200, false, player -> CommonPackets.sendSyncAutomobileAttachmentsPacket(this, player));
}
public ItemStack asPrefabItem() {
- var stack = new ItemStack(AutomobilityItems.AUTOMOBILE);
- var automobile = stack.getOrCreateSubNbt("Automobile");
+ var stack = new ItemStack(AutomobilityItems.AUTOMOBILE.require());
+ var automobile = stack.getOrCreateTagElement("Automobile");
automobile.putString("frame", frame.getId().toString());
automobile.putString("wheels", wheels.getId().toString());
automobile.putString("engine", engine.getId().toString());
@@ -685,16 +648,16 @@ public ItemStack asPrefabItem() {
@Nullable
@Override
- public ItemStack getPickBlockStack() {
+ public ItemStack getPickResult() {
return asPrefabItem();
}
// making mobs drive automobiles
// technically the mobs don't drive, instead the automobile
// self-drives to the mob's destination...
- public void provideMobDriverInputs(MobEntity driver) {
+ public void provideMobDriverInputs(Mob driver) {
// Don't move if the driver doesn't exist or can't drive
- if (driver == null || driver.isDead() || driver.isRemoved()) {
+ if (driver == null || driver.isDeadOrDying() || driver.isRemoved()) {
if (accelerating || steeringLeft || steeringRight) markDirty();
accelerating = false;
steeringLeft = false;
@@ -702,17 +665,17 @@ public void provideMobDriverInputs(MobEntity driver) {
return;
}
- var path = driver.getNavigation().getCurrentPath();
+ var path = driver.getNavigation().getPath();
// checks if there is a current, incomplete path that the entity has targeted
- if (path != null && !path.isFinished() && path.getEnd() != null) {
+ if (path != null && !path.isDone() && path.getEndNode() != null) {
// determines the relative position to drive to, based on the end of the path
- var pos = path.getEnd().getPos().subtract(getPos());
+ var pos = path.getEndNode().asVec3().subtract(position());
// determines the angle to that position
- double target = MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(pos.getX(), pos.getZ())));
+ double target = Mth.wrapDegrees(Math.toDegrees(Math.atan2(pos.x(), pos.z())));
// determines another relative position, this time to the path's current node (in the case of the path directly to the end being obstructed)
- var fnPos = path.getCurrentNode().getPos().subtract(getPos());
+ var fnPos = path.getNextNode().asVec3().subtract(position());
// determines the angle to that current node's position
- double fnTarget = MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(fnPos.getX(), fnPos.getZ())));
+ double fnTarget = Mth.wrapDegrees(Math.toDegrees(Math.atan2(fnPos.x(), fnPos.z())));
// if the difference in angle between the end position and the current node's position is too great,
// the automobile will drive to that current node under the assumption that the path directly to the
// end is obstructed
@@ -721,16 +684,16 @@ public void provideMobDriverInputs(MobEntity driver) {
target = fnTarget;
}
// fixes up the automobile's own yaw value
- float yaw = MathHelper.wrapDegrees(-getYaw());
+ float yaw = Mth.wrapDegrees(-getYRot());
// finds the difference between the target angle and the yaw
- double offset = MathHelper.wrapDegrees(yaw - target);
+ double offset = Mth.wrapDegrees(yaw - target);
// whether the automobile should go in reverse
boolean reverse = false;
// a value to determine the threshold used to determine whether the automobile is moving
// both slow enough and is at an extreme enough offset angle to incrementally move in reverse
- float mul = 0.5f + (MathHelper.clamp(hSpeed, 0, 1) * 0.5f);
+ float mul = 0.5f + (Mth.clamp(hSpeed, 0, 1) * 0.5f);
if (pos.length() < 20 * mul && Math.abs(offset) > 180 - (170 * mul)) {
- long time = world.getTime();
+ long time = level.getGameTime();
// this is so that the automobile alternates between reverse and forward,
// like a driver would do in order to angle their vehicle toward a target location
reverse = (time % 80 <= 30);
@@ -771,28 +734,28 @@ public void movementTick() {
// Get block below's friction
var blockBelow = new BlockPos(getX(), getY() - 0.05, getZ());
- this.grip = 1 - ((MathHelper.clamp((world.getBlockState(blockBelow).getBlock().getSlipperiness() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f)));
+ this.grip = 1 - ((Mth.clamp((level.getBlockState(blockBelow).getBlock().getFriction() - 0.6f) / 0.4f, 0, 1) * (1 - stats.getGrip() * 0.8f)));
this.grip *= this.grip;
// Bounce on gel
- if (this.automobileOnGround && this.jumpCooldown <= 0 && world.getBlockState(this.getBlockPos()).getBlock() instanceof LaunchGelBlock) {
+ if (this.automobileOnGround && this.jumpCooldown <= 0 && level.getBlockState(this.blockPosition()).getBlock() instanceof LaunchGelBlock) {
this.setSpeed(Math.max(this.getHSpeed(), 0.1f), Math.max(this.getVSpeed(), 0.9f));
this.jumpCooldown = 5;
this.automobileOnGround = false;
}
// Track the last position of the automobile
- this.lastPosForDisplacement = getPos();
+ this.lastPosForDisplacement = position();
// cumulative will be modified by the following code and then the automobile will be moved by it
// Currently initialized with the value of addedVelocity (which is a general velocity vector applied to the automobile, i.e. for when it bumps into a wall and is pushed back)
var cumulative = addedVelocity;
// Reduce gravity underwater
- cumulative = cumulative.add(0, (vSpeed * (isSubmergedInWater() ? 0.15f : 1)), 0);
+ cumulative = cumulative.add(0, (vSpeed * (isUnderWater() ? 0.15f : 1)), 0);
// This is the general direction the automobile will move, which is slightly offset to the side when drifting
- this.speedDirection = getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12); //MathHelper.lerp(grip, getYaw(), getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12));
+ this.speedDirection = getYRot() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12); //MathHelper.lerp(grip, getYaw(), getYaw() - (drifting ? Math.min(turboCharge * 6, 43 + (-steering * 12)) * driftDir : -steering * 12));
// Handle acceleration
if (accelerating) {
@@ -832,16 +795,16 @@ public void movementTick() {
// Allows for the sticky slope effect to continue for a tick after not being on a slope
// This prevents the automobile from randomly jumping if it's moving down a slope quickly
var below = new BlockPos(Math.floor(getX()), Math.floor(getY() - 0.51), Math.floor(getZ()));
- var state = world.getBlockState(below);
- if (state.isIn(Automobility.STICKY_SLOPES)) {
+ var state = level.getBlockState(below);
+ if (state.is(Automobility.STICKY_SLOPES)) {
slopeStickingTimer = 1;
} else {
slopeStickingTimer = Math.max(0, slopeStickingTimer--);
}
// Handle being in off-road
- if (boostSpeed < 0.4f && world.getBlockState(getBlockPos()).getBlock() instanceof OffRoadBlock offRoad) {
- int layers = world.getBlockState(getBlockPos()).get(OffRoadBlock.LAYERS);
+ if (boostSpeed < 0.4f && level.getBlockState(blockPosition()).getBlock() instanceof OffRoadBlock offRoad) {
+ int layers = level.getBlockState(blockPosition()).getValue(OffRoadBlock.LAYERS);
float cap = stats.getComfortableSpeed() * (1 - ((float)layers / 3.5f));
engineSpeed = Math.min(cap, engineSpeed);
this.debrisColor = offRoad.color;
@@ -865,7 +828,7 @@ public void movementTick() {
float angle = (float) Math.toRadians(-speedDirection);
if (this.burningOut()) {
if (Math.abs(hSpeed) > 0.02) {
- this.addedVelocity = new Vec3d(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed);
+ this.addedVelocity = new Vec3(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed);
this.hSpeed = 0;
cumulative = cumulative.add(addedVelocity);
}
@@ -874,9 +837,9 @@ public void movementTick() {
cumulative = cumulative.add(Math.sin(angle) * hSpeed, 0, Math.cos(angle) * hSpeed);
}
- cumulative = cumulative.multiply(this.grip).add(this.lastVelocity.multiply(1 - this.grip));
+ cumulative = cumulative.scale(this.grip).add(this.lastVelocity.scale(1 - this.grip));
if (cumulative.length() < 0.001) {
- cumulative = Vec3d.ZERO;
+ cumulative = Vec3.ZERO;
}
// Turn the wheels
@@ -885,11 +848,11 @@ public void movementTick() {
wheelAngle += 300 * (hSpeed / wheelCircumference) + (hSpeed > 0 ? ((1 - grip) * 15) : 0); // made it a bit slower intentionally, also make it spin more when on slippery surface
// Set the automobile's velocity
- if (this.isLogicalSideForUpdatingMovement()) {
- this.setVelocity(cumulative);
+ if (this.isControlledByLocalInstance()) {
+ this.setDeltaMovement(cumulative);
}
- this.scheduleVelocityUpdate();
- this.velocityDirty = true;
+ this.markHurt();
+ this.hasImpulse = true;
lastVelocity = cumulative;
@@ -899,15 +862,15 @@ public void movementTick() {
}
}
- public void runOverEntities(Vec3d velocity) {
- var frontBox = getBoundingBox().offset(velocity.multiply(0.5));
- var velAdd = velocity.add(0, 0.1, 0).multiply(3);
- for (var entity : world.getEntitiesByType(TypeFilter.instanceOf(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) {
+ public void runOverEntities(Vec3 velocity) {
+ var frontBox = getBoundingBox().move(velocity.scale(0.5));
+ var velAdd = velocity.add(0, 0.1, 0).scale(3);
+ for (var entity : level.getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger())) {
if (!entity.isInvulnerable()) {
if (entity instanceof LivingEntity living && entity.getVehicle() != this) {
- living.damage(AutomobilityEntities.AUTOMOBILE_DAMAGE_SOURCE, hSpeed * 10);
+ living.hurt(AutomobilityEntities.AUTOMOBILE_DAMAGE_SOURCE, hSpeed * 10);
- entity.addVelocity(velAdd.x, velAdd.y, velAdd.z);
+ entity.push(velAdd.x, velAdd.y, velAdd.z);
}
}
}
@@ -921,7 +884,7 @@ public void postMovementTick() {
// Reduce the values of addedVelocity incrementally
double addVelLen = addedVelocity.length();
- if (addVelLen > 0) addedVelocity = addedVelocity.multiply(Math.max(0, addVelLen - addedVelReduction) / addVelLen);
+ if (addVelLen > 0) addedVelocity = addedVelocity.scale(Math.max(0, addVelLen - addedVelReduction) / addVelLen);
float angle = (float) Math.toRadians(-speedDirection);
if (touchingWall && hSpeed > 0.1 && addedVelocity.length() <= 0) {
@@ -929,10 +892,10 @@ public void postMovementTick() {
double knockSpeed = ((-0.2 * hSpeed) - 0.5);
addedVelocity = addedVelocity.add(Math.sin(angle) * knockSpeed, 0, Math.cos(angle) * knockSpeed);
- world.playSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.COLLISION, SoundCategory.AMBIENT, 0.76f, 0.65f + (0.06f * (this.world.random.nextFloat() - 0.5f)), true);
+ level.playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.COLLISION.require(), SoundSource.AMBIENT, 0.76f, 0.65f + (0.06f * (this.level.random.nextFloat() - 0.5f)), true);
}
- double yDisp = getPos().subtract(this.lastPosForDisplacement).getY();
+ double yDisp = position().subtract(this.lastPosForDisplacement).y();
// Increment the falling timer
if (!automobileOnGround && yDisp < 0) {
@@ -947,7 +910,7 @@ public void postMovementTick() {
highestPrevYDisp = Math.max(d, highestPrevYDisp);
}
if (wasOnGround && !automobileOnGround && !isFloorDirectlyBelow) {
- vSpeed = (float)MathHelper.clamp(highestPrevYDisp, 0, hSpeed * 0.6f);
+ vSpeed = (float)Mth.clamp(highestPrevYDisp, 0, hSpeed * 0.6f);
}
// Handles gravity
@@ -975,7 +938,7 @@ public void postMovementTick() {
float acc = (1.7f / (1 + this.frame.weight())) + (4 * speed);
float lim = 9 + (4 * speed);
if (this.steering != 0) {
- newAngularSpeed = MathHelper.clamp(newAngularSpeed + (acc * this.steering), -lim, lim);
+ newAngularSpeed = Mth.clamp(newAngularSpeed + (acc * this.steering), -lim, lim);
} else {
newAngularSpeed = AUtils.shift(newAngularSpeed, acc * 0.5f, 0);
}
@@ -995,63 +958,63 @@ public void postMovementTick() {
// Turns the automobile based on steering/drifting
if (hSpeed != 0 || this.burningOut()) {
float yawInc = angularSpeed;// + (drifting ? (((this.steering + (driftDir)) * driftDir * 2.5f + 1.5f) * driftDir) * (((1 - stats.getGrip()) + 2) / 2.5f) : this.steering * ((4f * Math.min(hSpeed, 1)) + (hSpeed > 0 ? 2 : -3.5f))) * ((stats.getHandling() + 1) / 2);
- float prevYaw = getYaw();
- this.setYaw(getYaw() + yawInc);
- if (world.isClient) {
+ float prevYaw = getYRot();
+ this.setYRot(getYRot() + yawInc);
+ if (level.isClientSide) {
var passenger = getFirstPassenger();
- if (passenger instanceof PlayerEntity player) {
+ if (passenger instanceof Player player) {
if (inLockedViewMode()) {
- player.setYaw(MathHelper.wrapDegrees(getYaw() + lockedViewOffset));
- player.setBodyYaw(MathHelper.wrapDegrees(getYaw() + lockedViewOffset));
+ player.setYRot(Mth.wrapDegrees(getYRot() + lockedViewOffset));
+ player.setYBodyRot(Mth.wrapDegrees(getYRot() + lockedViewOffset));
} else {
- player.setYaw(MathHelper.wrapDegrees(player.getYaw() + yawInc));
- player.setBodyYaw(MathHelper.wrapDegrees(player.getYaw() + yawInc));
+ player.setYRot(Mth.wrapDegrees(player.getYRot() + yawInc));
+ player.setYBodyRot(Mth.wrapDegrees(player.getYRot() + yawInc));
}
}
} else {
- for (Entity e : getPassengerList()) {
+ for (Entity e : getPassengers()) {
if (e == getFirstPassenger()) {
- e.setYaw(MathHelper.wrapDegrees(e.getYaw() + yawInc));
- e.setBodyYaw(MathHelper.wrapDegrees(e.getYaw() + yawInc));
+ e.setYRot(Mth.wrapDegrees(e.getYRot() + yawInc));
+ e.setYBodyRot(Mth.wrapDegrees(e.getYRot() + yawInc));
}
}
}
- if (world.isClient()) {
- this.prevYaw = prevYaw;
+ if (level.isClientSide()) {
+ this.yRotO = prevYaw;
}
}
}
@Override
- public void move(MovementType movementType, Vec3d movement) {
- if (!this.world.isClient() && movementType == MovementType.PLAYER) {
+ public void move(MoverType movementType, Vec3 movement) {
+ if (!this.level.isClientSide() && movementType == MoverType.PLAYER) {
AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = true;
}
super.move(movementType, movement);
}
@Override
- public boolean handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) {
+ public boolean causeFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) {
return false; // Riders shouldn't take fall damage
}
public void accumulateCollisionAreas(Collection areas) {
- this.world.getEntitiesByClass(Entity.class, this.getBoundingBox().expand(3, 3, 3), e -> e != this && e.getVehicle() != this)
+ this.level.getEntitiesOfClass(Entity.class, this.getBoundingBox().inflate(3, 3, 3), e -> e != this && e.getVehicle() != this)
.forEach(e -> areas.add(CollisionArea.entity(e)));
}
public void displacementTick(boolean tick) {
- if (this.world.isClient()) {
+ if (this.level.isClientSide()) {
this.displacement.preTick();
if (tick) {
this.displacement.otherColliders.clear();
this.accumulateCollisionAreas(this.displacement.otherColliders);
- this.displacement.tick(this.world, this, this.getPos(), this.getYaw(), this.stepHeight);
+ this.displacement.tick(this.level, this, this.position(), this.getYRot(), this.maxUpStep);
}
- if (world.getBlockState(this.getBlockPos()).getBlock() instanceof AutomobileAssemblerBlock) {
+ if (level.getBlockState(this.blockPosition()).getBlock() instanceof AutomobileAssemblerBlock) {
this.displacement.lastVertical = this.displacement.verticalTarget = (-this.wheels.model().radius() / 16);
}
}
@@ -1067,31 +1030,31 @@ public void collisionStateTick() {
isFloorDirectlyBelow = false;
touchingWall = false;
var b = getBoundingBox();
- var groundBox = new Box(b.minX, b.minY - 0.04, b.minZ, b.maxX, b.minY, b.maxZ);
- var wid = (b.getXLength() + b.getZLength()) * 0.5f;
- var floorBox = new Box(b.minX + (wid * 0.94), b.minY - 0.05, b.minZ + (wid * 0.94), b.maxX - (wid * 0.94), b.minY, b.maxZ - (wid * 0.94));
- var wallBox = b.contract(0.05).offset(this.lastVelocity.normalize().multiply(0.12));
+ var groundBox = new AABB(b.minX, b.minY - 0.04, b.minZ, b.maxX, b.minY, b.maxZ);
+ var wid = (b.getXsize() + b.getZsize()) * 0.5f;
+ var floorBox = new AABB(b.minX + (wid * 0.94), b.minY - 0.05, b.minZ + (wid * 0.94), b.maxX - (wid * 0.94), b.minY, b.maxZ - (wid * 0.94));
+ var wallBox = b.deflate(0.05).move(this.lastVelocity.normalize().scale(0.12));
var start = new BlockPos(b.minX - 0.1, b.minY - 0.2, b.minZ - 0.1);
- var end = new BlockPos(b.maxX + 0.1, b.maxY + 0.2 + this.stepHeight, b.maxZ + 0.1);
- var groundCuboid = VoxelShapes.cuboid(groundBox);
- var floorCuboid = VoxelShapes.cuboid(floorBox);
- var wallCuboid = VoxelShapes.cuboid(wallBox);
- var stepWallCuboid = wallCuboid.offset(0, this.stepHeight - 0.05, 0);
+ var end = new BlockPos(b.maxX + 0.1, b.maxY + 0.2 + this.maxUpStep, b.maxZ + 0.1);
+ var groundCuboid = Shapes.create(groundBox);
+ var floorCuboid = Shapes.create(floorBox);
+ var wallCuboid = Shapes.create(wallBox);
+ var stepWallCuboid = wallCuboid.move(0, this.maxUpStep - 0.05, 0);
boolean wallHit = false;
boolean stepWallHit = false;
- var shapeCtx = ShapeContext.of(this);
- if (this.world.isRegionLoaded(start, end)) {
- var pos = new BlockPos.Mutable();
+ var shapeCtx = CollisionContext.of(this);
+ if (this.level.hasChunksAt(start, end)) {
+ var pos = new BlockPos.MutableBlockPos();
for(int x = start.getX(); x <= end.getX(); ++x) {
for(int y = start.getY(); y <= end.getY(); ++y) {
for(int z = start.getZ(); z <= end.getZ(); ++z) {
pos.set(x, y, z);
- var state = this.world.getBlockState(pos);
- var blockShape = state.getCollisionShape(this.world, pos, shapeCtx).offset(pos.getX(), pos.getY(), pos.getZ());
- this.automobileOnGround |= VoxelShapes.matchesAnywhere(blockShape, groundCuboid, BooleanBiFunction.AND);
- this.isFloorDirectlyBelow |= VoxelShapes.matchesAnywhere(blockShape, floorCuboid, BooleanBiFunction.AND);
- wallHit |= VoxelShapes.matchesAnywhere(blockShape, wallCuboid, BooleanBiFunction.AND);
- stepWallHit |= VoxelShapes.matchesAnywhere(blockShape, stepWallCuboid, BooleanBiFunction.AND);
+ var state = this.level.getBlockState(pos);
+ var blockShape = state.getCollisionShape(this.level, pos, shapeCtx).move(pos.getX(), pos.getY(), pos.getZ());
+ this.automobileOnGround |= Shapes.joinIsNotEmpty(blockShape, groundCuboid, BooleanOp.AND);
+ this.isFloorDirectlyBelow |= Shapes.joinIsNotEmpty(blockShape, floorCuboid, BooleanOp.AND);
+ wallHit |= Shapes.joinIsNotEmpty(blockShape, wallCuboid, BooleanOp.AND);
+ stepWallHit |= Shapes.joinIsNotEmpty(blockShape, stepWallCuboid, BooleanOp.AND);
}
}
}
@@ -1103,12 +1066,12 @@ public void collisionStateTick() {
this.automobileOnGround |= otherColliders.stream().anyMatch(col -> col.boxIntersects(groundBox));
}
- public void updateTrackedPositionAndAngles(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
+ public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
this.trackedX = x;
this.trackedY = y;
this.trackedZ = z;
this.trackedYaw = yaw;
- this.lerpTicks = this.getType().getTrackTickInterval() + 1;
+ this.lerpTicks = this.getType().updateInterval() + 1;
}
private float calculateAcceleration(float speed, AutomobileStats stats) {
@@ -1116,7 +1079,6 @@ private float calculateAcceleration(float speed, AutomobileStats stats) {
return (1 / ((300 * speed) + (18.5f - (stats.getAcceleration() * 5.3f)))) * (0.9f * ((stats.getAcceleration() + 1) / 2));
}
- @Environment(EnvType.CLIENT)
public void provideClientInput(boolean fwd, boolean back, boolean left, boolean right, boolean space) {
// Receives inputs client-side and sends them to the server
if (!(
@@ -1127,7 +1089,7 @@ public void provideClientInput(boolean fwd, boolean back, boolean left, boolean
space == holdingDrift
)) {
setInputs(fwd, back, left, right, space);
- PayloadPackets.sendSyncAutomobileInputPacket(this, accelerating, braking, steeringLeft, steeringRight, holdingDrift);
+ ClientPackets.sendSyncAutomobileInputPacket(this, accelerating, braking, steeringLeft, steeringRight, holdingDrift);
}
}
@@ -1144,7 +1106,7 @@ public void boost(float power, int time) {
boostTimer = time;
boostPower = power;
}
- if (this.isLogicalSideForUpdatingMovement()) {
+ if (this.isControlledByLocalInstance()) {
this.engineSpeed = Math.max(this.engineSpeed, this.stats.getComfortableSpeed() * 0.5f);
}
}
@@ -1183,7 +1145,7 @@ private void driftingTick() {
// Reduce speed when a drift starts, based on how long the last drift was for
// This allows you to do a series of short drifts without tanking all your speed, while still reducing your speed when you begin the drift(s)
engineSpeed -= 0.028 * engineSpeed;
- } else if (steering == 0 && !this.getWorld().isClient() && this.getRearAttachment() instanceof DeployableRearAttachment att) {
+ } else if (steering == 0 && !this.getLevel().isClientSide() && this.getRearAttachment() instanceof DeployableRearAttachment att) {
att.deploy();
}
}
@@ -1234,68 +1196,25 @@ private void burnoutTick() {
}
public void createDriftParticles() {
- var origin = this.getPos().add(0, this.displacement.verticalTarget, 0);
+ var origin = this.position().add(0, this.displacement.verticalTarget, 0);
for (var wheel : this.getFrame().model().wheelBase().wheels) {
if (wheel.end() == WheelBase.WheelEnd.BACK) {
- var pos = new Vec3d(wheel.right() + ((wheel.right() > 0 ? 1 : -1) * this.getWheels().model().width() * wheel.scale()), 0, wheel.forward())
- .rotateX((float) Math.toRadians(this.displacement.currAngularX))
- .rotateZ((float) Math.toRadians(this.displacement.currAngularZ))
- .rotateY((float) Math.toRadians(-this.getYaw())).multiply(0.0625).add(0, 0.4, 0);
- world.addParticle(AutomobilityParticles.DRIFT_SMOKE, origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0);
+ var pos = new Vec3(wheel.right() + ((wheel.right() > 0 ? 1 : -1) * this.getWheels().model().width() * wheel.scale()), 0, wheel.forward())
+ .xRot((float) Math.toRadians(this.displacement.currAngularX))
+ .zRot((float) Math.toRadians(this.displacement.currAngularZ))
+ .yRot((float) Math.toRadians(-this.getYRot())).scale(0.0625).add(0, 0.4, 0);
+ level.addParticle(AutomobilityParticles.DRIFT_SMOKE.require(), origin.x + pos.x, origin.y + pos.y, origin.z + pos.z, 0, 0, 0);
}
}
}
private static boolean inLockedViewMode() {
- return ControllerUtils.inControllerMode();
- }
-
- @Environment(EnvType.CLIENT)
- private void updateModels(EntityRendererFactory.Context ctx) {
- if (updateModels) {
- this.frameModel = frame.model().model().apply(ctx);
- this.wheelModel = wheels.model().model().apply(ctx);
- this.engineModel = engine.model().model().apply(ctx);
- this.rearAttachmentModel = this.rearAttachment.type.model().model().apply(ctx);
- this.frontAttachmentModel = this.frontAttachment.type.model().model().apply(ctx);
-
- updateModels = false;
- }
- }
-
- @Environment(EnvType.CLIENT)
- public Model getWheelModel(EntityRendererFactory.Context ctx) {
- updateModels(ctx);
- return wheelModel;
- }
-
- @Environment(EnvType.CLIENT)
- public Model getFrameModel(EntityRendererFactory.Context ctx) {
- updateModels(ctx);
- return frameModel;
- }
-
- @Environment(EnvType.CLIENT)
- public Model getEngineModel(EntityRendererFactory.Context ctx) {
- updateModels(ctx);
- return engineModel;
- }
-
- @Override
- public @Nullable Model getRearAttachmentModel(EntityRendererFactory.Context ctx) {
- updateModels(ctx);
- return rearAttachmentModel;
- }
-
- @Override
- public @Nullable Model getFrontAttachmentModel(EntityRendererFactory.Context ctx) {
- updateModels(ctx);
- return frontAttachmentModel;
+ return Platform.get().inControllerMode();
}
@Override
public float getAutomobileYaw(float tickDelta) {
- return getYaw(tickDelta);
+ return getViewYRot(tickDelta);
}
@Override
@@ -1305,7 +1224,7 @@ public float getRearAttachmentYaw(float tickDelta) {
@Nullable
@Override
- public Entity getPrimaryPassenger() {
+ public Entity getControllingPassenger() {
return getFirstPassenger();
}
@@ -1320,10 +1239,10 @@ public boolean hasInventory() {
}
@Override
- public void openInventory(PlayerEntity player) {
- var factory = this.getRearAttachment().createMenu(new AutomobileScreenHandlerContext(this));
+ public void openInventory(Player player) {
+ var factory = this.getRearAttachment().createMenu(new AutomobileContainerLevelAccess(this));
if (factory != null) {
- player.openHandledScreen(factory);
+ player.openMenu(factory);
}
}
@@ -1331,25 +1250,25 @@ public float getStandStillTime() {
return this.standStillTime;
}
- public void playHitSound(Vec3d pos) {
- world.emitGameEvent(this, GameEvent.ENTITY_DAMAGE, pos);
- world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.BLOCK_COPPER_BREAK, SoundCategory.AMBIENT, 1, 0.9f + (this.world.random.nextFloat() * 0.2f));
+ public void playHitSound(Vec3 pos) {
+ level.gameEvent(this, GameEvent.ENTITY_DAMAGE, pos);
+ level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.COPPER_BREAK, SoundSource.AMBIENT, 1, 0.9f + (this.level.random.nextFloat() * 0.2f));
}
- private void dropParts(Vec3d pos) {
- world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.createStack(this.getFrame())));
- world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.createStack(this.getEngine())));
+ private void dropParts(Vec3 pos) {
+ level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_FRAME.require().createStack(this.getFrame())));
+ level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, AutomobilityItems.AUTOMOBILE_ENGINE.require().createStack(this.getEngine())));
- var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.createStack(this.getWheels());
+ var wheelStack = AutomobilityItems.AUTOMOBILE_WHEEL.require().createStack(this.getWheels());
wheelStack.setCount(this.getFrame().model().wheelBase().wheelCount);
- world.spawnEntity(new ItemEntity(world, pos.x, pos.y, pos.z, wheelStack));
+ level.addFreshEntity(new ItemEntity(level, pos.x, pos.y, pos.z, wheelStack));
}
public void destroyRearAttachment(boolean drop) {
if (drop) {
var dropPos = this.rearAttachment.pos();
- world.spawnEntity(new ItemEntity(world, dropPos.x, dropPos.y, dropPos.z,
- AutomobilityItems.REAR_ATTACHMENT.createStack(this.getRearAttachmentType())));
+ level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z,
+ AutomobilityItems.REAR_ATTACHMENT.require().createStack(this.getRearAttachmentType())));
}
this.setRearAttachment(RearAttachmentType.EMPTY);
}
@@ -1357,8 +1276,8 @@ public void destroyRearAttachment(boolean drop) {
public void destroyFrontAttachment(boolean drop) {
if (drop) {
var dropPos = this.frontAttachment.pos();
- world.spawnEntity(new ItemEntity(world, dropPos.x, dropPos.y, dropPos.z,
- AutomobilityItems.FRONT_ATTACHMENT.createStack(this.getFrontAttachmentType())));
+ level.addFreshEntity(new ItemEntity(level, dropPos.x, dropPos.y, dropPos.z,
+ AutomobilityItems.FRONT_ATTACHMENT.require().createStack(this.getFrontAttachmentType())));
}
this.setFrontAttachment(FrontAttachmentType.EMPTY);
}
@@ -1371,44 +1290,44 @@ public void destroyAutomobile(boolean drop, RemovalReason reason) {
this.destroyFrontAttachment(drop);
}
if (drop) {
- this.dropParts(this.getPos().add(0, 0.3, 0));
+ this.dropParts(this.position().add(0, 0.3, 0));
}
this.remove(reason);
}
@Override
- public ActionResult interact(PlayerEntity player, Hand hand) {
- if (player.isSneaking()) {
+ public InteractionResult interact(Player player, InteractionHand hand) {
+ if (player.isShiftKeyDown()) {
if (this.hasInventory()) {
- if (!world.isClient()) {
+ if (!level.isClientSide()) {
openInventory(player);
- return ActionResult.PASS;
+ return InteractionResult.PASS;
} else {
- return ActionResult.SUCCESS;
+ return InteractionResult.SUCCESS;
}
}
}
- var stack = player.getStackInHand(hand);
- if ((!this.decorative || player.isCreative()) && stack.isOf(AutomobilityItems.CROWBAR)) {
+ var stack = player.getItemInHand(hand);
+ if ((!this.decorative || player.isCreative()) && stack.is(AutomobilityItems.CROWBAR.require())) {
double playerAngle = Math.toDegrees(Math.atan2(player.getZ() - this.getZ(), player.getX() - this.getX()));
- double angleDiff = MathHelper.wrapDegrees(this.getYaw() - playerAngle);
+ double angleDiff = Mth.wrapDegrees(this.getYRot() - playerAngle);
if (angleDiff < 0 && !this.frontAttachment.type.isEmpty()) {
this.destroyFrontAttachment(!player.isCreative());
this.playHitSound(this.getHeadPos());
- return ActionResult.success(world.isClient);
+ return InteractionResult.sidedSuccess(level.isClientSide);
} else if (!this.rearAttachment.type.isEmpty()) {
this.destroyRearAttachment(!player.isCreative());
this.playHitSound(this.rearAttachment.pos());
- return ActionResult.success(world.isClient);
+ return InteractionResult.sidedSuccess(level.isClientSide);
} else {
this.destroyAutomobile(!player.isCreative(), RemovalReason.KILLED);
- this.playHitSound(this.getPos());
+ this.playHitSound(this.position());
- return ActionResult.success(world.isClient);
+ return InteractionResult.sidedSuccess(level.isClientSide);
}
}
@@ -1418,61 +1337,61 @@ public ActionResult interact(PlayerEntity player, Hand hand) {
}
if (!this.hasSpaceForPassengers()) {
- if (!(this.getFirstPassenger() instanceof PlayerEntity)) {
- if (!world.isClient()) {
+ if (!(this.getFirstPassenger() instanceof Player)) {
+ if (!level.isClientSide()) {
this.getFirstPassenger().stopRiding();
}
- return ActionResult.success(world.isClient);
+ return InteractionResult.sidedSuccess(level.isClientSide);
}
- return ActionResult.PASS;
+ return InteractionResult.PASS;
}
- if (!world.isClient()) {
+ if (!level.isClientSide()) {
player.startRiding(this);
}
- return ActionResult.success(world.isClient());
+ return InteractionResult.sidedSuccess(level.isClientSide());
}
- return ActionResult.PASS;
+ return InteractionResult.PASS;
}
@Override
- public double getMountedHeightOffset() {
+ public double getPassengersRidingOffset() {
return ((wheels.model().radius() + frame.model().seatHeight() - 4) / 16);
}
@Override
- public void updatePassengerPosition(Entity passenger) {
+ public void positionRider(Entity passenger) {
if (passenger == this.getFirstPassenger()) {
- var pos = this.getPos().add(0, this.displacement.verticalTarget + passenger.getHeightOffset(), 0)
- .add(new Vec3d(0, this.getMountedHeightOffset(), 0)
- .rotateX((float) Math.toRadians(-this.displacement.currAngularX))
- .rotateZ((float) Math.toRadians(-this.displacement.currAngularZ)));
+ var pos = this.position().add(0, this.displacement.verticalTarget + passenger.getMyRidingOffset(), 0)
+ .add(new Vec3(0, this.getPassengersRidingOffset(), 0)
+ .xRot((float) Math.toRadians(-this.displacement.currAngularX))
+ .zRot((float) Math.toRadians(-this.displacement.currAngularZ)));
- passenger.setPosition(pos.x, pos.y, pos.z);
+ passenger.setPos(pos.x, pos.y, pos.z);
} else if (this.hasPassenger(passenger)) {
- var pos = this.getPos().add(
- new Vec3d(0, this.displacement.verticalTarget, this.getFrame().model().rearAttachmentPos() * 0.0625)
- .rotateY((float) Math.toRadians(180 - this.getYaw())).add(0, this.rearAttachment.getPassengerHeightOffset() + passenger.getHeightOffset() - 0.14, 0)
+ var pos = this.position().add(
+ new Vec3(0, this.displacement.verticalTarget, this.getFrame().model().rearAttachmentPos() * 0.0625)
+ .yRot((float) Math.toRadians(180 - this.getYRot())).add(0, this.rearAttachment.getPassengerHeightOffset() + passenger.getMyRidingOffset() - 0.14, 0)
.add(this.rearAttachment.scaledYawVec())
- .rotateX((float) Math.toRadians(-this.displacement.currAngularX))
- .rotateZ((float) Math.toRadians(-this.displacement.currAngularZ)));
+ .xRot((float) Math.toRadians(-this.displacement.currAngularX))
+ .zRot((float) Math.toRadians(-this.displacement.currAngularZ)));
- passenger.setPosition(pos.x, pos.y, pos.z);
+ passenger.setPos(pos.x, pos.y, pos.z);
}
}
@Override
- public boolean collidesWith(Entity other) {
- return BoatEntity.canCollide(this, other);
+ public boolean canCollideWith(Entity other) {
+ return Boat.canVehicleCollide(this, other);
}
@Override
- public boolean isCollidable() {
+ public boolean canBeCollidedWith() {
return true;
}
@Override
- public boolean canHit() {
+ public boolean isPickable() {
return !this.isRemoved();
}
@@ -1482,14 +1401,14 @@ public boolean isPushable() {
}
@Override
- protected void initDataTracker() {
- this.dataTracker.startTracking(REAR_ATTACHMENT_YAW, 0f);
- this.dataTracker.startTracking(REAR_ATTACHMENT_ANIMATION, 0f);
+ protected void defineSynchedData() {
+ this.entityData.define(REAR_ATTACHMENT_YAW, 0f);
+ this.entityData.define(REAR_ATTACHMENT_ANIMATION, 0f);
}
@Override
- public void onTrackedDataSet(TrackedData> data) {
- super.onTrackedDataSet(data);
+ public void onSyncedDataUpdated(EntityDataAccessor> data) {
+ super.onSyncedDataUpdated(data);
if (REAR_ATTACHMENT_YAW.equals(data)) {
this.rearAttachment.onTrackedYawUpdated(getTrackedRearAttachmentYaw());
@@ -1501,37 +1420,37 @@ public void onTrackedDataSet(TrackedData> data) {
}
@Override
- public Packet> createSpawnPacket() {
- return new EntitySpawnS2CPacket(this);
+ public Packet> getAddEntityPacket() {
+ return new ClientboundAddEntityPacket(this);
}
public void setTrackedRearAttachmentYaw(float value) {
- this.dataTracker.set(REAR_ATTACHMENT_YAW, value);
+ this.entityData.set(REAR_ATTACHMENT_YAW, value);
}
public float getTrackedRearAttachmentYaw() {
- return this.dataTracker.get(REAR_ATTACHMENT_YAW);
+ return this.entityData.get(REAR_ATTACHMENT_YAW);
}
public void setTrackedRearAttachmentAnimation(float animation) {
- this.dataTracker.set(REAR_ATTACHMENT_ANIMATION, animation);
+ this.entityData.set(REAR_ATTACHMENT_ANIMATION, animation);
}
public float getTrackedRearAttachmentAnimation() {
- return this.dataTracker.get(REAR_ATTACHMENT_ANIMATION);
+ return this.entityData.get(REAR_ATTACHMENT_ANIMATION);
}
public void setTrackedFrontAttachmentAnimation(float animation) {
- this.dataTracker.set(FRONT_ATTACHMENT_ANIMATION, animation);
+ this.entityData.set(FRONT_ATTACHMENT_ANIMATION, animation);
}
public float getTrackedFrontAttachmentAnimation() {
- return this.dataTracker.get(FRONT_ATTACHMENT_ANIMATION);
+ return this.entityData.get(FRONT_ATTACHMENT_ANIMATION);
}
public void bounce() {
suspensionBounceTimer = 3;
- world.playSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING, SoundCategory.AMBIENT, 1, 1.5f + (0.15f * (this.world.random.nextFloat() - 0.5f)), true);
+ level.playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING.require(), SoundSource.AMBIENT, 1, 1.5f + (0.15f * (this.level.random.nextFloat() - 0.5f)), true);
}
public static final class Displacement {
@@ -1547,7 +1466,7 @@ public static final class Displacement {
private float verticalTarget = 0;
private float angularXTarget = 0;
private float angularZTarget = 0;
- private final List scanPoints = new ArrayList<>();
+ private final List scanPoints = new ArrayList<>();
public final Set otherColliders = new HashSet<>();
public void preTick() {
@@ -1559,17 +1478,17 @@ public void preTick() {
this.currAngularZ = AUtils.shift(this.currAngularZ, 9, this.angularZTarget);
}
- public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double yaw, double stepHeight) {
+ public void tick(Level world, AutomobileEntity entity, Vec3 centerPos, double yaw, double stepHeight) {
yaw = 360 - yaw;
- Vec3d lowestDisplacementPos = null;
- Vec3d highestDisplacementPos = null;
- var scannedPoints = new ArrayList();
+ Vec3 lowestDisplacementPos = null;
+ Vec3 highestDisplacementPos = null;
+ var scannedPoints = new ArrayList();
var colliders = new HashSet();
boolean anyOnGround = false;
boolean allOnGround = true;
for (var scanPoint : scanPoints) {
scanPoint = scanPoint
- .rotateY((float) Math.toRadians(yaw));
+ .yRot((float) Math.toRadians(yaw));
var pointPos = scanPoint.add(centerPos);
colliders.clear();
colliders.addAll(this.otherColliders);
@@ -1577,7 +1496,7 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
double scanDist = scanPoint.length();
int heightOffset = (int) Math.ceil(scanDist);
- var iter = new CuboidBlockIterator(
+ var iter = new Cursor3D(
(int) Math.min(Math.floor(centerPos.x), Math.floor(pointPos.x)),
(int) Math.floor(centerPos.y) - heightOffset,
(int) Math.min(Math.floor(centerPos.z), Math.floor(pointPos.z)),
@@ -1586,21 +1505,21 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
(int) Math.max(Math.floor(centerPos.z), Math.floor(pointPos.z))
);
- var mpos = new BlockPos.Mutable();
- while (iter.step()) {
- mpos.set(iter.getX(), iter.getY(), iter.getZ());
+ var mpos = new BlockPos.MutableBlockPos();
+ while (iter.advance()) {
+ mpos.set(iter.nextX(), iter.nextY(), iter.nextZ());
var shape = world.getBlockState(mpos).getCollisionShape(world, mpos);
if (!shape.isEmpty()) {
- if (shape == VoxelShapes.fullCube()) {
+ if (shape == Shapes.block()) {
colliders.add(CollisionArea.box(mpos.getX(), mpos.getY() - (INV_SCAN_STEPS * 2), mpos.getZ(), mpos.getX() + 1, mpos.getY() + 1, mpos.getZ() + 1));
} else {
- shape.offset(mpos.getX(), mpos.getY(), mpos.getZ()).forEachBox(((minX, minY, minZ, maxX, maxY, maxZ) ->
+ shape.move(mpos.getX(), mpos.getY(), mpos.getZ()).forAllBoxes(((minX, minY, minZ, maxX, maxY, maxZ) ->
colliders.add(CollisionArea.box(minX, minY - (INV_SCAN_STEPS * 2), minZ, maxX, maxY, maxZ))));
}
}
}
- var pointDir = new Vec3d(scanPoint.x, 0, scanPoint.z).normalize().multiply(INV_SCAN_STEPS);
+ var pointDir = new Vec3(scanPoint.x, 0, scanPoint.z).normalize().scale(INV_SCAN_STEPS);
double pointY = centerPos.y;
for (int i = 0; i < Math.ceil(scanDist * SCAN_STEPS_PER_BLOCK); i++) {
@@ -1626,7 +1545,7 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
}
}
- pointPos = new Vec3d(pointPos.x, pointY, pointPos.z);
+ pointPos = new Vec3(pointPos.x, pointY, pointPos.z);
if (lowestDisplacementPos == null || pointPos.y < lowestDisplacementPos.y) {
lowestDisplacementPos = pointPos;
@@ -1652,45 +1571,45 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
verticalTarget = 0;
if (lowestDisplacementPos != null) {
- var displacementCenterPos = new Vec3d(centerPos.x, (lowestDisplacementPos.y + highestDisplacementPos.y) * 0.5, centerPos.z);
+ var displacementCenterPos = new Vec3(centerPos.x, (lowestDisplacementPos.y + highestDisplacementPos.y) * 0.5, centerPos.z);
- var combinedNormals = Vec3d.ZERO;
+ var combinedNormals = Vec3.ZERO;
int normalCount = 0;
- Vec3d positiveXOffset = null;
- Vec3d negativeXOffset = null;
- Vec3d positiveZOffset = null;
- Vec3d negativeZOffset = null;
+ Vec3 positiveXOffset = null;
+ Vec3 negativeXOffset = null;
+ Vec3 positiveZOffset = null;
+ Vec3 negativeZOffset = null;
for (var pointPos : scannedPoints) {
var pointOffset = pointPos.subtract(displacementCenterPos);
if (pointOffset.x > 0) {
if (positiveXOffset != null) {
- var normal = positiveXOffset.crossProduct(pointOffset).normalize();
- if (normal.y < 0) normal = normal.negate();
+ var normal = positiveXOffset.cross(pointOffset).normalize();
+ if (normal.y < 0) normal = normal.reverse();
combinedNormals = combinedNormals.add(normal);
normalCount++;
positiveXOffset = null;
} else positiveXOffset = pointOffset;
} else if (pointOffset.x < 0) {
if (negativeXOffset != null) {
- var normal = negativeXOffset.crossProduct(pointOffset).normalize();
- if (normal.y < 0) normal = normal.negate();
+ var normal = negativeXOffset.cross(pointOffset).normalize();
+ if (normal.y < 0) normal = normal.reverse();
combinedNormals = combinedNormals.add(normal);
normalCount++;
negativeXOffset = null;
} else negativeXOffset = pointOffset;
} else if (pointOffset.z > 0) {
if (positiveZOffset != null) {
- var normal = positiveZOffset.crossProduct(pointOffset).normalize();
- if (normal.y < 0) normal = normal.negate();
+ var normal = positiveZOffset.cross(pointOffset).normalize();
+ if (normal.y < 0) normal = normal.reverse();
combinedNormals = combinedNormals.add(normal);
normalCount++;
positiveZOffset = null;
} else positiveZOffset = pointOffset;
} else if (pointOffset.z < 0) {
if (negativeZOffset != null) {
- var normal = negativeZOffset.crossProduct(pointOffset).normalize();
- if (normal.y < 0) normal = normal.negate();
+ var normal = negativeZOffset.cross(pointOffset).normalize();
+ if (normal.y < 0) normal = normal.reverse();
combinedNormals = combinedNormals.add(normal);
normalCount++;
negativeZOffset = null;
@@ -1698,10 +1617,10 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
}
}
- combinedNormals = normalCount > 0 ? combinedNormals.multiply(1f / normalCount) : new Vec3d(0, 1, 0);
+ combinedNormals = normalCount > 0 ? combinedNormals.scale(1f / normalCount) : new Vec3(0, 1, 0);
- angularXTarget = MathHelper.wrapDegrees(90f - (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.z)));
- angularZTarget = MathHelper.wrapDegrees(270f + (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.x)));
+ angularXTarget = Mth.wrapDegrees(90f - (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.z)));
+ angularZTarget = Mth.wrapDegrees(270f + (float) Math.toDegrees(Math.atan2(combinedNormals.y, combinedNormals.x)));
verticalTarget = (float) displacementCenterPos.subtract(centerPos).y;
}
@@ -1710,20 +1629,20 @@ public void tick(World world, AutomobileEntity entity, Vec3d centerPos, double y
public void applyWheelbase(WheelBase wheelBase) {
this.scanPoints.clear();
for (WheelBase.WheelPos pos : wheelBase.wheels) {
- this.scanPoints.add(new Vec3d(pos.right() / 16, 0, pos.forward() / 16));
+ this.scanPoints.add(new Vec3(pos.right() / 16, 0, pos.forward() / 16));
}
}
public float getVertical(float tickDelta) {
- return MathHelper.lerp(tickDelta, lastVertical, verticalTarget);
+ return Mth.lerp(tickDelta, lastVertical, verticalTarget);
}
public float getAngularX(float tickDelta) {
- return MathHelper.lerpAngleDegrees(tickDelta, lastAngularX, currAngularX);
+ return Mth.rotLerp(tickDelta, lastAngularX, currAngularX);
}
public float getAngularZ(float tickDelta) {
- return MathHelper.lerpAngleDegrees(tickDelta, lastAngularZ, currAngularZ);
+ return Mth.rotLerp(tickDelta, lastAngularZ, currAngularZ);
}
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java
new file mode 100644
index 0000000..db4eb41
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobilityEntities.java
@@ -0,0 +1,26 @@
+package io.github.foundationgames.automobility.entity;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.platform.Platform;
+import io.github.foundationgames.automobility.util.Eventual;
+import io.github.foundationgames.automobility.util.RegistryQueue;
+import net.minecraft.core.Registry;
+import net.minecraft.tags.TagKey;
+import net.minecraft.world.damagesource.DamageSource;
+import net.minecraft.world.entity.EntityDimensions;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.MobCategory;
+
+public enum AutomobilityEntities {;
+ public static final Eventual> AUTOMOBILE = RegistryQueue.register(Registry.ENTITY_TYPE,
+ Automobility.rl("automobile"),
+ () -> Platform.get().entityType(MobCategory.MISC, AutomobileEntity::new, new EntityDimensions(1f, 0.66f, true), 3, 10)
+ );
+
+ public static final TagKey> DASH_PANEL_BOOSTABLES = TagKey.create(Registry.ENTITY_TYPE_REGISTRY, Automobility.rl("dash_panel_boostables"));
+
+ public static final DamageSource AUTOMOBILE_DAMAGE_SOURCE = new AutomobileDamageSource("automobile");
+
+ public static void init() {
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java b/common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java
rename to common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java
index 691dbd8..243ad7c 100644
--- a/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/entity/EntityWithInventory.java
@@ -1,9 +1,9 @@
package io.github.foundationgames.automobility.entity;
-import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.world.entity.player.Player;
public interface EntityWithInventory {
boolean hasInventory();
- void openInventory(PlayerEntity player);
+ void openInventory(Player player);
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java
new file mode 100644
index 0000000..0abb6a7
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java
@@ -0,0 +1,36 @@
+package io.github.foundationgames.automobility.entity.render;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Quaternion;
+import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.entity.EntityRenderer;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.client.renderer.texture.OverlayTexture;
+import net.minecraft.resources.ResourceLocation;
+
+public class AutomobileEntityRenderer extends EntityRenderer {
+ public AutomobileEntityRenderer(EntityRendererProvider.Context ctx) {
+ super(ctx);
+ }
+
+ @Override
+ public ResourceLocation getTextureLocation(AutomobileEntity entity) {
+ return null;
+ }
+
+ @Override
+ public void render(AutomobileEntity entity, float yaw, float tickDelta, PoseStack pose, MultiBufferSource buffers, int light) {
+ pose.pushPose();
+ float angX = entity.getDisplacement().getAngularX(tickDelta);
+ float angZ = entity.getDisplacement().getAngularZ(tickDelta);
+ float offsetY = entity.getDisplacement().getVertical(tickDelta);
+
+ pose.translate(0, offsetY, 0);
+ pose.mulPose(Quaternion.fromXYZ((float) Math.toRadians(angX), 0, (float) Math.toRadians(angZ)));
+
+ AutomobileRenderer.render(pose, buffers, light, OverlayTexture.NO_OVERLAY, tickDelta, entity);
+ pose.popPose();
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java
new file mode 100644
index 0000000..2eb2ca9
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileComponentItem.java
@@ -0,0 +1,78 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.automobile.AutomobileComponent;
+import io.github.foundationgames.automobility.util.SimpleMapContentRegistry;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.NonNullList;
+import net.minecraft.network.chat.Component;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.CreativeModeTab;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.TooltipFlag;
+import net.minecraft.world.level.Level;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class AutomobileComponentItem> extends Item {
+ protected final String nbtKey;
+ protected final String translationKey;
+ protected final SimpleMapContentRegistry registry;
+
+ public AutomobileComponentItem(Properties settings, String nbtKey, String translationKey, SimpleMapContentRegistry registry) {
+ super(settings);
+ this.nbtKey = nbtKey;
+ this.translationKey = translationKey;
+ this.registry = registry;
+ }
+
+ public ItemStack createStack(T component) {
+ if (component.isEmpty()) {
+ return ItemStack.EMPTY;
+ }
+
+ var stack = new ItemStack(this);
+ this.setComponent(stack, component.getId());
+ return stack;
+ }
+
+ public void setComponent(ItemStack stack, ResourceLocation component) {
+ stack.getOrCreateTag().putString(this.nbtKey, component.toString());
+ }
+
+ public T getComponent(ItemStack stack) {
+ if (stack.hasTag() && stack.getTag().contains(this.nbtKey)) {
+ return this.registry.getOrDefault(ResourceLocation.tryParse(stack.getTag().getString(this.nbtKey)));
+ }
+ return this.registry.getOrDefault(null);
+ }
+
+ @Override
+ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) {
+ super.appendHoverText(stack, world, tooltip, context);
+ var component = this.getComponent(stack);
+ var id = component.getId();
+ var compKey = id.getNamespace()+"."+id.getPath();
+ tooltip.add(Component.translatable(this.translationKey+"."+compKey).withStyle(ChatFormatting.BLUE));
+
+ component.appendTexts(tooltip, component);
+ }
+
+ @Override
+ public void fillItemCategory(CreativeModeTab group, NonNullList stacks) {
+ if (this.allowedIn(group)) {
+ this.registry.forEach(component -> {
+ if (addToCreative(component)) stacks.add(this.createStack(component));
+ });
+ }
+ }
+
+ public boolean isVisible(T component) {
+ return !component.isEmpty();
+ }
+
+ protected boolean addToCreative(T component) {
+ return !component.isEmpty();
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java
similarity index 84%
rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java
rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java
index d664541..8f508f0 100644
--- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileEngineItem.java
@@ -3,7 +3,7 @@
import io.github.foundationgames.automobility.automobile.AutomobileEngine;
public class AutomobileEngineItem extends AutomobileComponentItem {
- public AutomobileEngineItem(Settings settings) {
+ public AutomobileEngineItem(Properties settings) {
super(settings, "engine", "engine", AutomobileEngine.REGISTRY);
}
}
diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java
similarity index 89%
rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java
rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java
index b58ddd1..e834397 100644
--- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileFrameItem.java
@@ -3,7 +3,7 @@
import io.github.foundationgames.automobility.automobile.AutomobileFrame;
public class AutomobileFrameItem extends AutomobileComponentItem {
- public AutomobileFrameItem(Settings settings) {
+ public AutomobileFrameItem(Properties settings) {
super(settings, "frame", "frame", AutomobileFrame.REGISTRY);
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java
new file mode 100644
index 0000000..db85876
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileInteractable.java
@@ -0,0 +1,11 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
+
+public interface AutomobileInteractable {
+ InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile);
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java
new file mode 100644
index 0000000..6e755cf
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileItem.java
@@ -0,0 +1,88 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.automobile.AutomobileData;
+import io.github.foundationgames.automobility.automobile.AutomobilePrefab;
+import io.github.foundationgames.automobility.automobile.AutomobileStats;
+import io.github.foundationgames.automobility.entity.AutomobileEntity;
+import io.github.foundationgames.automobility.entity.AutomobilityEntities;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.core.NonNullList;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.item.CreativeModeTab;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.TooltipFlag;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.level.Level;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class AutomobileItem extends Item {
+ public static final List PREFABS = new ArrayList<>();
+ private static final AutomobileData data = new AutomobileData();
+ private static final AutomobileStats stats = new AutomobileStats();
+
+ public AutomobileItem(Properties settings) {
+ super(settings);
+ }
+
+ @Override
+ public InteractionResult useOn(UseOnContext context) {
+ if (!context.getLevel().isClientSide()) {
+ var stack = context.getItemInHand();
+ data.read(stack.getOrCreateTagElement("Automobile"));
+ var e = new AutomobileEntity(AutomobilityEntities.AUTOMOBILE.require(), context.getLevel());
+ var pos = context.getClickLocation();
+ e.moveTo(pos.x, pos.y, pos.z, context.getHorizontalDirection().toYRot(), 0);
+ e.setComponents(data.getFrame(), data.getWheel(), data.getEngine());
+ context.getLevel().addFreshEntity(e);
+ stack.shrink(1);
+ return InteractionResult.PASS;
+ }
+ return InteractionResult.SUCCESS;
+ }
+
+ @Override
+ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) {
+ super.appendHoverText(stack, world, tooltip, context);
+ data.read(stack.getOrCreateTagElement("Automobile"));
+ if (Screen.hasShiftDown()) {
+ stats.from(data.getFrame(), data.getWheel(), data.getEngine());
+ stats.appendTexts(tooltip, stats);
+ } else {
+ if (!data.isPrefab()) {
+ tooltip.add(
+ Component.translatable("tooltip.automobility.frameLabel").withStyle(ChatFormatting.BLUE)
+ .append(Component.translatable(data.getFrame().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN))
+ );
+ tooltip.add(
+ Component.translatable("tooltip.automobility.wheelLabel").withStyle(ChatFormatting.BLUE)
+ .append(Component.translatable(data.getWheel().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN))
+ );
+ tooltip.add(
+ Component.translatable("tooltip.automobility.engineLabel").withStyle(ChatFormatting.BLUE)
+ .append(Component.translatable(data.getEngine().getTranslationKey()).withStyle(ChatFormatting.DARK_GREEN))
+ );
+ }
+ tooltip.add(Component.translatable("tooltip.automobility.shiftForStats").withStyle(ChatFormatting.GOLD));
+ }
+ }
+
+ public static void addPrefabs(AutomobilePrefab ... prefabs) {
+ PREFABS.addAll(Arrays.asList(prefabs));
+ }
+
+ @Override
+ public void fillItemCategory(CreativeModeTab group, NonNullList stacks) {
+ if (allowedIn(group) || group == CreativeModeTab.TAB_TRANSPORTATION) {
+ for (var prefab : PREFABS) {
+ stacks.add(prefab.toStack());
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java
similarity index 89%
rename from src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java
rename to common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java
index b2c2983..8ae99bc 100644
--- a/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobileWheelItem.java
@@ -3,7 +3,7 @@
import io.github.foundationgames.automobility.automobile.AutomobileWheel;
public class AutomobileWheelItem extends AutomobileComponentItem {
- public AutomobileWheelItem(Settings settings) {
+ public AutomobileWheelItem(Properties settings) {
super(settings, "wheel", "wheel", AutomobileWheel.REGISTRY);
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java
new file mode 100644
index 0000000..f45545f
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/AutomobilityItems.java
@@ -0,0 +1,66 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.Automobility;
+import io.github.foundationgames.automobility.automobile.AutomobileEngine;
+import io.github.foundationgames.automobility.automobile.AutomobileFrame;
+import io.github.foundationgames.automobility.automobile.AutomobilePrefab;
+import io.github.foundationgames.automobility.automobile.AutomobileWheel;
+import io.github.foundationgames.automobility.util.Eventual;
+import io.github.foundationgames.automobility.util.RegistryQueue;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.Registry;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.item.Item;
+
+import java.util.function.Supplier;
+
+public enum AutomobilityItems {;
+ public static final Eventual- CROWBAR = register("crowbar", () -> new TooltipItem(Component.translatable("tooltip.item.automobility.crowbar").withStyle(ChatFormatting.BLUE), new Item.Properties().stacksTo(1).tab(Automobility.GROUP)));
+ public static final Eventual
- AUTOMOBILE = register("automobile", () -> new AutomobileItem(new Item.Properties().stacksTo(1).tab(Automobility.PREFABS)));
+ public static final Eventual AUTOMOBILE_FRAME = register("automobile_frame", () -> new AutomobileFrameItem(new Item.Properties().stacksTo(16).tab(Automobility.GROUP)));
+ public static final Eventual AUTOMOBILE_WHEEL = register("automobile_wheel", () -> new AutomobileWheelItem(new Item.Properties().tab(Automobility.GROUP)));
+ public static final Eventual AUTOMOBILE_ENGINE = register("automobile_engine", () -> new AutomobileEngineItem(new Item.Properties().stacksTo(16).tab(Automobility.GROUP)));
+ public static final Eventual FRONT_ATTACHMENT = register("front_attachment", () -> new FrontAttachmentItem(new Item.Properties().stacksTo(1).tab(Automobility.GROUP)));
+ public static final Eventual REAR_ATTACHMENT = register("rear_attachment", () -> new RearAttachmentItem(new Item.Properties().stacksTo(1).tab(Automobility.GROUP)));
+
+ public static void init() {
+ AutomobileItem.addPrefabs(
+ new AutomobilePrefab(Automobility.rl("wooden_motorcar"), AutomobileFrame.WOODEN_MOTORCAR, AutomobileWheel.CARRIAGE, AutomobileEngine.STONE),
+ new AutomobilePrefab(Automobility.rl("copper_motorcar"), AutomobileFrame.COPPER_MOTORCAR, AutomobileWheel.PLATED, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("steel_motorcar"), AutomobileFrame.STEEL_MOTORCAR, AutomobileWheel.STREET, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("golden_motorcar"), AutomobileFrame.GOLDEN_MOTORCAR, AutomobileWheel.GILDED, AutomobileEngine.GOLD),
+ new AutomobilePrefab(Automobility.rl("bejeweled_motorcar"), AutomobileFrame.BEJEWELED_MOTORCAR, AutomobileWheel.BEJEWELED, AutomobileEngine.DIAMOND),
+ new AutomobilePrefab(Automobility.rl("standard_white"), AutomobileFrame.STANDARD_WHITE, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_orange"), AutomobileFrame.STANDARD_ORANGE, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_magenta"), AutomobileFrame.STANDARD_MAGENTA, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_light_blue"), AutomobileFrame.STANDARD_LIGHT_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_yellow"), AutomobileFrame.STANDARD_YELLOW, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_lime"), AutomobileFrame.STANDARD_LIME, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_pink"), AutomobileFrame.STANDARD_PINK, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_gray"), AutomobileFrame.STANDARD_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_light_gray"), AutomobileFrame.STANDARD_LIGHT_GRAY, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_cyan"), AutomobileFrame.STANDARD_CYAN, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_purple"), AutomobileFrame.STANDARD_PURPLE, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_blue"), AutomobileFrame.STANDARD_BLUE, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_brown"), AutomobileFrame.STANDARD_BROWN, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_green"), AutomobileFrame.STANDARD_GREEN, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_red"), AutomobileFrame.STANDARD_RED, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("standard_black"), AutomobileFrame.STANDARD_BLACK, AutomobileWheel.STANDARD, AutomobileEngine.IRON),
+ new AutomobilePrefab(Automobility.rl("amethyst_rickshaw"), AutomobileFrame.AMETHYST_RICKSHAW, AutomobileWheel.BEJEWELED, AutomobileEngine.STONE),
+ new AutomobilePrefab(Automobility.rl("quartz_rickshaw"), AutomobileFrame.QUARTZ_RICKSHAW, AutomobileWheel.GILDED, AutomobileEngine.GOLD),
+ new AutomobilePrefab(Automobility.rl("prismarine_rickshaw"), AutomobileFrame.PRISMARINE_RICKSHAW, AutomobileWheel.PLATED, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("echo_rickshaw"), AutomobileFrame.ECHO_RICKSHAW, AutomobileWheel.STREET, AutomobileEngine.DIAMOND),
+ new AutomobilePrefab(Automobility.rl("red_tractor"), AutomobileFrame.RED_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("yellow_tractor"), AutomobileFrame.YELLOW_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("green_tractor"), AutomobileFrame.GREEN_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("blue_tractor"), AutomobileFrame.BLUE_TRACTOR, AutomobileWheel.TRACTOR, AutomobileEngine.COPPER),
+ new AutomobilePrefab(Automobility.rl("shopping_cart"), AutomobileFrame.SHOPPING_CART, AutomobileWheel.STEEL, AutomobileEngine.STONE),
+ new AutomobilePrefab(Automobility.rl("c_arr"), AutomobileFrame.C_ARR, AutomobileWheel.OFF_ROAD, AutomobileEngine.DIAMOND),
+ new AutomobilePrefab(Automobility.rl("pineapple"), AutomobileFrame.PINEAPPLE, AutomobileWheel.TRACTOR, AutomobileEngine.GOLD)
+ );
+ }
+
+ public static Eventual register(String name, Supplier item) {
+ return RegistryQueue.register(Registry.ITEM, Automobility.rl(name), item);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java
new file mode 100644
index 0000000..13a83cd
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java
@@ -0,0 +1,64 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.block.AutomobilityBlocks;
+import io.github.foundationgames.automobility.block.SlopeBlock;
+import io.github.foundationgames.automobility.block.SteepSlopeBlock;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.chat.Component;
+import net.minecraft.sounds.SoundEvents;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import org.jetbrains.annotations.Nullable;
+
+public class DashPanelItem extends TooltipBlockItem {
+ private static final Component TOOLTIP = Component.translatable("tooltip.block.automobility.dash_panel")
+ .withStyle(ChatFormatting.BLUE);
+
+ public DashPanelItem(Block block, Properties settings) {
+ super(block, TOOLTIP, settings);
+ }
+
+ @Override
+ public InteractionResult useOn(UseOnContext ctx) {
+ var lvl = ctx.getLevel();
+ var pos = ctx.getClickedPos();
+ var state = lvl.getBlockState(pos);
+
+ if (state.is(AutomobilityBlocks.SLOPE.require())) {
+ if (!lvl.isClientSide()) {
+ ctx.getLevel().setBlockAndUpdate(pos, AutomobilityBlocks.SLOPE_WITH_DASH_PANEL.require()
+ .withPropertiesOf(state));
+ }
+ afterPlace(ctx.getItemInHand(), lvl, ctx.getPlayer(), pos);
+
+ return InteractionResult.SUCCESS;
+ }
+ if (state.is(AutomobilityBlocks.STEEP_SLOPE.require())) {
+ if (!lvl.isClientSide()) {
+ ctx.getLevel().setBlockAndUpdate(pos, AutomobilityBlocks.STEEP_SLOPE_WITH_DASH_PANEL.require()
+ .withPropertiesOf(state));
+ }
+ afterPlace(ctx.getItemInHand(), lvl, ctx.getPlayer(), pos);
+
+ return InteractionResult.SUCCESS;
+ }
+
+ return super.useOn(ctx);
+ }
+
+ private void afterPlace(ItemStack stack, Level level, @Nullable Player player, BlockPos pos) {
+ if (!level.isClientSide()) {
+ level.playSound(null, pos, SoundEvents.METAL_PLACE, SoundSource.BLOCKS, 1, 1.25f);
+
+ if (player == null || !player.isCreative()) {
+ stack.shrink(1);
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java
rename to common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java
index 37fc1e0..3a4682a 100644
--- a/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/FrontAttachmentItem.java
@@ -2,30 +2,30 @@
import io.github.foundationgames.automobility.automobile.attachment.FrontAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.ActionResult;
-import net.minecraft.util.Hand;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
public class FrontAttachmentItem extends AutomobileComponentItem> implements AutomobileInteractable {
- public FrontAttachmentItem(Settings settings) {
+ public FrontAttachmentItem(Properties settings) {
super(settings, "attachment", "attachment.front", FrontAttachmentType.REGISTRY);
}
@Override
- public ActionResult interactAutomobile(ItemStack stack, PlayerEntity player, Hand hand, AutomobileEntity automobile) {
+ public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) {
if (automobile.getFrontAttachment().type.isEmpty()) {
- if (player.world.isClient()) {
- return ActionResult.SUCCESS;
+ if (player.level.isClientSide()) {
+ return InteractionResult.SUCCESS;
}
automobile.setFrontAttachment(getComponent(stack));
automobile.playHitSound(automobile.getHeadPos());
if (!player.isCreative()) {
- stack.decrement(1);
+ stack.shrink(1);
}
}
- return ActionResult.PASS;
+ return InteractionResult.PASS;
}
}
\ No newline at end of file
diff --git a/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java
rename to common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java
index a11cdbc..6a44cfd 100644
--- a/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/RearAttachmentItem.java
@@ -2,30 +2,30 @@
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.util.ActionResult;
-import net.minecraft.util.Hand;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.ItemStack;
public class RearAttachmentItem extends AutomobileComponentItem> implements AutomobileInteractable {
- public RearAttachmentItem(Settings settings) {
+ public RearAttachmentItem(Properties settings) {
super(settings, "attachment", "attachment.rear", RearAttachmentType.REGISTRY);
}
@Override
- public ActionResult interactAutomobile(ItemStack stack, PlayerEntity player, Hand hand, AutomobileEntity automobile) {
+ public InteractionResult interactAutomobile(ItemStack stack, Player player, InteractionHand hand, AutomobileEntity automobile) {
if (automobile.getRearAttachment().type.isEmpty()) {
- if (player.world.isClient()) {
- return ActionResult.SUCCESS;
+ if (player.level.isClientSide()) {
+ return InteractionResult.SUCCESS;
}
automobile.setRearAttachment(getComponent(stack));
automobile.playHitSound(automobile.getTailPos());
if (!player.isCreative()) {
- stack.decrement(1);
+ stack.shrink(1);
}
}
- return ActionResult.PASS;
+ return InteractionResult.PASS;
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java
new file mode 100644
index 0000000..2c1aafe
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/SlopeBlockItem.java
@@ -0,0 +1,41 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.block.SlopeBlock;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.level.block.state.properties.Half;
+import org.jetbrains.annotations.Nullable;
+
+public class SlopeBlockItem extends BlockItem {
+ public SlopeBlockItem(Block block, Properties settings) {
+ super(block, settings);
+ }
+
+ @Nullable
+ @Override
+ public BlockPlaceContext updatePlacementContext(BlockPlaceContext context) {
+ var hitPos = context.getClickLocation();
+ var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z));
+ var world = context.getLevel();
+ if (world.getBlockState(pos).getBlock() instanceof SlopeBlock) {
+ var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING);
+ var half = world.getBlockState(pos).getValue(BlockStateProperties.HALF);
+ var playerFacing = context.getHorizontalDirection();
+ var vOffset = playerFacing == facing && half == Half.BOTTOM ? Direction.DOWN : playerFacing == facing.getOpposite() && half == Half.TOP ? Direction.UP : null;
+ var place = pos.relative(playerFacing);
+ if (vOffset != null) place = place.relative(vOffset);
+ var pState = world.getBlockState(place);
+ var nHalf = half;
+ if (playerFacing == facing || playerFacing == facing.getOpposite()) nHalf = half == Half.TOP ? Half.BOTTOM : Half.TOP;
+ if (pState.isAir() || pState.is(Blocks.WATER)) {
+ return new SlopePlacementContext(BlockPlaceContext.at(context, place, Direction.UP), facing, nHalf);
+ }
+ }
+ return super.updatePlacementContext(context);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java b/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java
new file mode 100644
index 0000000..07380fd
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/SlopePlacementContext.java
@@ -0,0 +1,29 @@
+package io.github.foundationgames.automobility.item;
+
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.level.block.state.properties.Half;
+
+public class SlopePlacementContext extends BlockPlaceContext {
+ private final Direction slopeFacing;
+ private final Half slopeHalf;
+
+ public SlopePlacementContext(UseOnContext context, Direction slopeFacing, Half slopeHalf) {
+ super(context);
+ this.slopeFacing = slopeFacing;
+ this.slopeHalf = slopeHalf;
+ }
+
+ public SlopePlacementContext(UseOnContext context, Direction slopeFacing) {
+ this(context, slopeFacing, Half.BOTTOM);
+ }
+
+ public Direction getSlopeFacing() {
+ return slopeFacing;
+ }
+
+ public Half getSlopeHalf() {
+ return slopeHalf;
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java
new file mode 100644
index 0000000..e6083b6
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/SteepSlopeBlockItem.java
@@ -0,0 +1,37 @@
+package io.github.foundationgames.automobility.item;
+
+import io.github.foundationgames.automobility.block.SteepSlopeBlock;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.context.BlockPlaceContext;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import org.jetbrains.annotations.Nullable;
+
+public class SteepSlopeBlockItem extends BlockItem {
+ public SteepSlopeBlockItem(Block block, Properties settings) {
+ super(block, settings);
+ }
+
+ @Nullable
+ @Override
+ public BlockPlaceContext updatePlacementContext(BlockPlaceContext context) {
+ var hitPos = context.getClickLocation();
+ var pos = new BlockPos(Math.floor(hitPos.x), Math.floor(hitPos.y), Math.floor(hitPos.z));
+ var world = context.getLevel();
+ if (world.getBlockState(pos).getBlock() instanceof SteepSlopeBlock) {
+ var facing = world.getBlockState(pos).getValue(BlockStateProperties.HORIZONTAL_FACING);
+ var playerFacing = context.getHorizontalDirection();
+ var vOffset = playerFacing == facing ? Direction.DOWN : playerFacing == facing.getOpposite() ? Direction.UP : null;
+ var place = pos.relative(playerFacing);
+ if (vOffset != null) place = place.relative(vOffset);
+ var pState = world.getBlockState(place);
+ if (pState.isAir() || pState.is(Blocks.WATER)) {
+ return new SlopePlacementContext(BlockPlaceContext.at(context, place, Direction.UP), facing);
+ }
+ }
+ return super.updatePlacementContext(context);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java
new file mode 100644
index 0000000..2b0c180
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipBlockItem.java
@@ -0,0 +1,26 @@
+package io.github.foundationgames.automobility.item;
+
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.TooltipFlag;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.Block;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class TooltipBlockItem extends BlockItem {
+ private final Component tooltip;
+
+ public TooltipBlockItem(Block block, Component tooltip, Properties settings) {
+ super(block, settings);
+ this.tooltip = tooltip;
+ }
+
+ @Override
+ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) {
+ super.appendHoverText(stack, world, tooltip, context);
+ tooltip.add(this.tooltip);
+ }
+}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java
new file mode 100644
index 0000000..7eba5a5
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/item/TooltipItem.java
@@ -0,0 +1,25 @@
+package io.github.foundationgames.automobility.item;
+
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.TooltipFlag;
+import net.minecraft.world.level.Level;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class TooltipItem extends Item {
+ private final Component tooltip;
+
+ public TooltipItem(Component tooltip, Properties settings) {
+ super(settings);
+ this.tooltip = tooltip;
+ }
+
+ @Override
+ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) {
+ super.appendHoverText(stack, world, tooltip, context);
+ tooltip.add(this.tooltip);
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java
similarity index 64%
rename from src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java
rename to common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java
index 01220cc..b703e75 100644
--- a/src/main/java/io/github/foundationgames/automobility/mixin/BoxMixin.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/AABBMixin.java
@@ -1,26 +1,26 @@
package io.github.foundationgames.automobility.mixin;
import io.github.foundationgames.automobility.util.duck.CollisionArea;
-import net.minecraft.util.math.Box;
+import net.minecraft.world.phys.AABB;
import org.spongepowered.asm.mixin.Mixin;
-@Mixin(Box.class)
-public class BoxMixin implements CollisionArea {
+@Mixin(AABB.class)
+public class AABBMixin implements CollisionArea {
@Override
public boolean isPointInside(double x, double y, double z) {
- var self = (Box)(Object)this;
+ var self = (AABB)(Object)this;
return (x >= self.minX && x <= self.maxX) &&
(y >= self.minY && y <= self.maxY) &&
(z >= self.minZ && z <= self.maxZ);
}
@Override
- public boolean boxIntersects(Box box) {
- return ((Box)(Object)this).intersects(box);
+ public boolean boxIntersects(AABB box) {
+ return ((AABB)(Object)this).intersects(box);
}
@Override
public double highestY(double x, double y, double z) {
- return ((Box)(Object)this).maxY;
+ return ((AABB)(Object)this).maxY;
}
}
diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java
new file mode 100644
index 0000000..3bc36a7
--- /dev/null
+++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/AbstractContainerMenuMixin.java
@@ -0,0 +1,26 @@
+package io.github.foundationgames.automobility.mixin;
+
+import io.github.foundationgames.automobility.screen.AutomobileContainerLevelAccess;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.inventory.AbstractContainerMenu;
+import net.minecraft.world.inventory.ContainerLevelAccess;
+import net.minecraft.world.level.block.Block;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+@Mixin(AbstractContainerMenu.class)
+public class AbstractContainerMenuMixin {
+ @Inject(
+ method = "stillValid(Lnet/minecraft/world/inventory/ContainerLevelAccess;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/Block;)Z",
+ at = @At("HEAD"), cancellable = true)
+ private static void automobility$spoofAutomobileAttachmentScreens(ContainerLevelAccess context, Player player, Block block, CallbackInfoReturnable cir) {
+ if (context instanceof AutomobileContainerLevelAccess ctx) {
+ boolean isClose = ctx.evaluate((world, pos) -> (player.blockPosition().distSqr(pos) < 64), true);
+ if (isClose && ctx.getAttachmentBlockState().is(block)) {
+ cir.setReturnValue(true);
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java
similarity index 62%
rename from src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java
rename to common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java
index 1f75acd..3f18862 100644
--- a/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java
@@ -1,8 +1,8 @@
package io.github.foundationgames.automobility.mixin;
import io.github.foundationgames.automobility.util.AUtils;
-import net.minecraft.entity.Entity;
-import net.minecraft.util.math.Vec3d;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -15,16 +15,16 @@ public class EntityMixin {
@Shadow protected boolean onGround;
- @Inject(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At("HEAD"))
- private void automobility$spoofGroundStart(Vec3d movement, CallbackInfoReturnable cir) {
+ @Inject(method = "collide", at = @At("HEAD"))
+ private void automobility$spoofGroundStart(Vec3 movement, CallbackInfoReturnable cir) {
if (AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING) {
this.automobility$cacheOnGround = this.onGround;
this.onGround = true;
}
}
- @Inject(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At("TAIL"))
- private void automobility$spoofGroundEnd(Vec3d movement, CallbackInfoReturnable cir) {
+ @Inject(method = "collide", at = @At("TAIL"))
+ private void automobility$spoofGroundEnd(Vec3 movement, CallbackInfoReturnable cir) {
if (AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING) {
this.onGround = this.automobility$cacheOnGround;
AUtils.IGNORE_ENTITY_GROUND_CHECK_STEPPING = false;
diff --git a/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java
similarity index 57%
rename from src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java
rename to common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java
index ef51a2e..56a6709 100644
--- a/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java
+++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityRenderersMixin.java
@@ -1,10 +1,10 @@
package io.github.foundationgames.automobility.mixin;
import io.github.foundationgames.automobility.util.EntityRenderHelper;
-import net.minecraft.client.render.entity.EntityRenderer;
-import net.minecraft.client.render.entity.EntityRendererFactory;
-import net.minecraft.client.render.entity.EntityRenderers;
-import net.minecraft.entity.EntityType;
+import net.minecraft.client.renderer.entity.EntityRenderer;
+import net.minecraft.client.renderer.entity.EntityRendererProvider;
+import net.minecraft.client.renderer.entity.EntityRenderers;
+import net.minecraft.world.entity.EntityType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -14,8 +14,8 @@
@Mixin(EntityRenderers.class)
public class EntityRenderersMixin {
- @Inject(method = "reloadEntityRenderers", at = @At("HEAD"))
- private static void automobility$reloadContextListeners(EntityRendererFactory.Context ctx, CallbackInfoReturnable