-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added rickshaws - Added paver and backhoe - Fixed bugs with automobile assembler
- Loading branch information
1 parent
edae5b5
commit c5271bf
Showing
38 changed files
with
1,753 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...github/foundationgames/automobility/automobile/attachment/rear/BackhoeRearAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ithub/foundationgames/automobility/automobile/attachment/rear/BasePlowRearAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...hub/foundationgames/automobility/automobile/attachment/rear/DeployableRearAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
81 changes: 81 additions & 0 deletions
81
...hub/foundationgames/automobility/automobile/attachment/rear/ExtendableRearAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...o/github/foundationgames/automobility/automobile/attachment/rear/PaverRearAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.