Skip to content

Commit

Permalink
Version 0.3
Browse files Browse the repository at this point in the history
- Added rickshaws
- Added paver and backhoe
- Fixed bugs with automobile assembler
  • Loading branch information
FoundationGames committed Nov 13, 2022
1 parent edae5b5 commit c5271bf
Show file tree
Hide file tree
Showing 38 changed files with 1,753 additions and 51 deletions.
10 changes: 1 addition & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

static String terraformersUrl() {
def url = "https://maven.terraformersmc.com/"
def conn = new URL(url).openConnection()
conn.connect()
url = conn.getResponseCode() == 521 ? "https://raw.githubusercontent.com/TerraformersMC/Archive/main/releases" : url
return url
}

repositories {
maven { url = "https://maven.gegy.dev/" }
maven { url = terraformersUrl() }
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/" }
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ org.gradle.jvmargs=-Xmx1G

minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.13.3
loader_version=0.14.8

#Fabric api
fabric_version=0.51.1+1.18.2
fabric_version=0.56.0+1.18.2

# Other Dependencies
midnightcontrols_version=1.4.1-1.18
Expand All @@ -15,6 +15,6 @@ myron_version=1.6.3+1.18.1
arrp_version=0.5.5
jsonem_version=0.1.2

mod_version = 0.2.2+1.18.2
mod_version = 0.3+1.18.2
maven_group = io.github.foundationgames
archives_base_name = automobility
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public record AutomobileFrame(
public static final AutomobileFrame STANDARD_RED = REGISTRY.register(standard("red"));
public static final AutomobileFrame STANDARD_BLACK = REGISTRY.register(standard("black"));

public static final AutomobileFrame AMETHYST_RICKSHAW = REGISTRY.register(rickshaw("amethyst", 0.2f));
public static final AutomobileFrame QUARTZ_RICKSHAW = REGISTRY.register(rickshaw("quartz", 0.25f));
public static final AutomobileFrame PRISMARINE_RICKSHAW = REGISTRY.register(rickshaw("prismarine", 0.14f));

public static final AutomobileFrame RED_TRACTOR = REGISTRY.register(tractor("red"));
public static final AutomobileFrame YELLOW_TRACTOR = REGISTRY.register(tractor("yellow"));
public static final AutomobileFrame GREEN_TRACTOR = REGISTRY.register(tractor("green"));
Expand Down Expand Up @@ -192,6 +196,29 @@ private static AutomobileFrame tractor(String color) {
);
}

private static AutomobileFrame rickshaw(String prefix, float weight) {
return new AutomobileFrame(
Automobility.id(prefix+"_rickshaw"),
weight,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/"+prefix+"_rickshaw.png"),
Automobility.id("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),
new WheelBase.WheelPos(11, -0.1f, 1, 0, WheelBase.WheelEnd.FRONT, WheelBase.WheelSide.LEFT),
new WheelBase.WheelPos(11, 0.1f, 1, 180, WheelBase.WheelEnd.FRONT, WheelBase.WheelSide.RIGHT)
),
26,
2.5f,
13,
3,
17.5f,
14.5f
)
);
}

public static final DisplayStat<AutomobileFrame> STAT_WEIGHT = new DisplayStat<>("weight", AutomobileFrame::weight);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.AutomobileComponent;
import io.github.foundationgames.automobility.automobile.DisplayStat;
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.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;
Expand Down Expand Up @@ -54,6 +56,16 @@ public record RearAttachmentType<T extends RearAttachment>(
new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/banner_post.png"), Automobility.id("rearatt_banner_post"), 10)
));

public static final RearAttachmentType<BackhoeRearAttachment> 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)
));

public static final RearAttachmentType<PaverRearAttachment> 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)
));

@Override
public boolean isEmpty() {
return this == EMPTY;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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.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 java.util.List;

public class BackhoeRearAttachment extends BasePlowRearAttachment {
public static final List<Block> TILLABLE_BLOCKS = List.of(Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.DIRT_PATH);

public BackhoeRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) {
super(type, entity);
}

@Override
public SoundEvent plowSound() {
return SoundEvents.ITEM_HOE_TILL;
}

@Override
public double searchHeight() {
return -0.25;
}

@Override
public BlockState plowResult(BlockPos pos, BlockState state) {
if (!this.world().getBlockState(pos.up()).isAir()) {
return state;
}

return TILLABLE_BLOCKS.contains(state.getBlock()) ? Blocks.FARMLAND.getDefaultState() : state;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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.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;

public abstract class BasePlowRearAttachment extends ExtendableRearAttachment {
private final BlockPos.Mutable blockIter = new BlockPos.Mutable();
private Vec3d lastPos = null;

public BasePlowRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) {
super(type, entity);
this.setExtended(true);
}

@Override
public void tick() {
super.tick();
var pos = this.origin().add(this.yawVec().multiply(0.11 * this.type.model().pivotDistPx()));

if (this.extended() && canModifyBlocks() && lastPos != null && lastPos.subtract(pos).length() > 0.03 && this.world() instanceof ServerWorld world) {
this.plow(pos, world);
}

this.lastPos = pos;
}

public void plow(Vec3d pos, ServerWorld 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);
int maxZ = (int) Math.floor(pos.z + 0.5);
int y = (int) Math.floor(pos.y + this.searchHeight());

boolean playSound = false;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
blockIter.set(x, y, z);
var state = world.getBlockState(blockIter);
var result = this.plowResult(blockIter, state);

if (result != state) {
world.setBlockState(blockIter, result);
playSound = true;
}
}
}

if (playSound) {
world.playSound(null, pos.x, pos.y, pos.z, this.plowSound(), SoundCategory.BLOCKS, 0.8f, 1f);
}
}

@Override
public void setExtended(boolean deployed) {
if (!world().isClient() && 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);
}

super.setExtended(deployed);
}

public abstract SoundEvent plowSound();

public abstract double searchHeight();

public abstract BlockState plowResult(BlockPos pos, BlockState state);

@Override
protected int extendAnimTime() {
return 3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.foundationgames.automobility.automobile.attachment.rear;

import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;

public abstract class DeployableRearAttachment extends RearAttachment {

protected DeployableRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) {
super(type, entity);
}

public abstract void deploy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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.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;

public abstract class ExtendableRearAttachment extends DeployableRearAttachment {
protected boolean extended;

private int extendAnimation = 0;
private int lastExtendAnimation = extendAnimation;

protected ExtendableRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) {
super(type, entity);
}

public float extendAnimation(float delta) {
return MathHelper.lerp(delta, lastExtendAnimation, extendAnimation) / 14;
}

public void setExtended(boolean extended) {
if (!this.world().isClient()) {
this.updateTrackedAnimation(extended ? 1f : 0f);
}

this.extended = extended;
}

public boolean extended() {
return this.extended;
}

@Override
public void tick() {
super.tick();

if (this.world().isClient()) {
this.lastExtendAnimation = this.extendAnimation;
this.extendAnimation = AUtils.shift(this.extendAnimation, 1, this.extended() ? 0 : this.extendAnimTime());
}
}

@Override
public void updatePacketRequested(ServerPlayerEntity player) {
super.updatePacketRequested(player);

PayloadPackets.sendExtendableAttachmentUpdatePacket(this.automobile(), this.extended(), player);
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

nbt.putBoolean("extended", this.extended());
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);

this.setExtended(nbt.getBoolean("extended"));
}

@Override
public void deploy() {
this.setExtended(!this.extended());
}

@Override
public void onTrackedAnimationUpdated(float animation) {
super.onTrackedAnimationUpdated(animation);

this.setExtended(animation > 0);
}

protected abstract int extendAnimTime();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.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;

public class PaverRearAttachment extends BasePlowRearAttachment {
public PaverRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) {
super(type, entity);
}

@Override
public SoundEvent plowSound() {
return SoundEvents.ITEM_SHOVEL_FLATTEN;
}

@Override
public double searchHeight() {
return -0.25;
}

@Override
public BlockState plowResult(BlockPos pos, BlockState state) {
if (!this.world().getBlockState(pos.up()).isAir()) {
return state;
}

return ShovelItemAccess.getPathStates().getOrDefault(state.getBlock(), state);
}
}
Loading

0 comments on commit c5271bf

Please sign in to comment.