Skip to content

Commit

Permalink
Allow extended pistons to merge with crafts (#539)
Browse files Browse the repository at this point in the history
* Merge piston extensions with crafts.

* Clean up imports

* Remove debug messages

* Remove debug messages

* Fix craft files

* Make requested changes

---------

Co-authored-by: TylerS1066 <[email protected]>
  • Loading branch information
HumorousFool and TylerS1066 authored Sep 5, 2023
1 parent 61aa121 commit aa33964
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.PilotedCraft;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.localisation.I18nSupport;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.util.MathUtils;
import net.countercraft.movecraft.util.Tags;
import org.bukkit.Bukkit;
import net.countercraft.movecraft.util.hitboxes.BitmapHitBox;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -47,6 +47,7 @@
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.material.Attachable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

public class BlockListener implements Listener {
Expand Down Expand Up @@ -154,9 +155,19 @@ public void onPistonEvent(BlockPistonExtendEvent event) {
Block block = event.getBlock();
CraftManager.getInstance().getCraftsInWorld(block.getWorld());
for (Craft tcraft : CraftManager.getInstance().getCraftsInWorld(block.getWorld())) {
MovecraftLocation mloc = new MovecraftLocation(block.getX(), block.getY(), block.getZ());
if (MathUtils.locIsNearCraftFast(tcraft, mloc) && tcraft.getCruising() && !tcraft.isNotProcessing()) {
if(tcraft == null || !MathUtils.locationInHitBox(tcraft.getHitBox(), block.getLocation()))
continue;

if (tcraft.getCruising() && !tcraft.isNotProcessing()) {
event.setCancelled(true);
}
else if(tcraft.getType().getBoolProperty(CraftType.MERGE_PISTON_EXTENSIONS)){
BitmapHitBox hitBox = new BitmapHitBox();
for (Block b : event.getBlocks()) {
Vector dir = event.getDirection().getDirection();
hitBox.add(new MovecraftLocation(b.getX() + dir.getBlockX(), b.getY() + dir.getBlockY(), b.getZ() + dir.getBlockZ()));
}
tcraft.setHitBox(tcraft.getHitBox().union(hitBox));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Movecraft/src/main/resources/types/Elevator.craft
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ detectionMultiplier: 30.0
underwaterDetectionMultiplier: 3.0
speed: 1.0
tryNudge: false
sinkPercent: 99.0
sinkPercent: 99.0
2 changes: 1 addition & 1 deletion modules/Movecraft/src/main/resources/types/Submarine.craft
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ flyblocks:
- 1.0
iron_block:
- 15.0
- 100.0
- 100.0
2 changes: 1 addition & 1 deletion modules/Movecraft/src/main/resources/types/Turret.craft
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ allowHorizontalMovement: false
allowVerticalMovement: false
speed: 1.0
tryNudge: false
sinkPercent: 99.0
sinkPercent: 99.0
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ final public class CraftType {
public static final NamespacedKey GEAR_SHIFTS_AFFECT_CRUISE_SKIP_BLOCKS = buildKey(
"gear_shifts_affect_cruise_skip_blocks");
public static final NamespacedKey RELEASE_TIMEOUT = buildKey("release_timeout");
public static final NamespacedKey MERGE_PISTON_EXTENSIONS = buildKey("merge_piston_extensions");
//endregion

@Contract("_ -> new")
Expand Down Expand Up @@ -558,6 +559,7 @@ else if (o instanceof Integer)
type -> false
));
registerProperty(new IntegerProperty("releaseTimeout", RELEASE_TIMEOUT, type -> 30));
registerProperty(new BooleanProperty("mergePistonExtensions", MERGE_PISTON_EXTENSIONS, type -> false));

/* Craft type transforms */
// Convert speed to TICK_COOLDOWN
Expand Down

0 comments on commit aa33964

Please sign in to comment.