Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extended pistons to merge with crafts #539

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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