From 7bdaf01f374438a98919244008a26f99f8d22067 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Fri, 26 Jul 2024 09:37:59 +0200 Subject: [PATCH] magnets will now also call piston logic to determine moveable stuff. Gravisand has inverted movement when pulled by magnets --- .../addons/oddities/block/be/MagnetBlockEntity.java | 4 +++- .../addons/oddities/magnetsystem/MagnetSystem.java | 11 +++++++++++ .../quark/addons/oddities/module/MagnetsModule.java | 3 +++ .../content/experimental/config/VariantsConfig.java | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/be/MagnetBlockEntity.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/be/MagnetBlockEntity.java index 32c51c20f..a5f717a3b 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/be/MagnetBlockEntity.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/be/MagnetBlockEntity.java @@ -17,6 +17,7 @@ import org.violetmoon.quark.addons.oddities.magnetsystem.MagnetSystem; import org.violetmoon.quark.addons.oddities.module.MagnetsModule; import org.violetmoon.quark.api.IMagneticEntity; +import org.violetmoon.quark.content.automation.entity.Gravisand; import org.violetmoon.quark.content.experimental.module.VariantSelectorModule; import org.violetmoon.quark.mixin.mixins.accessor.AccessorServerGamePacketListener; import org.violetmoon.zeta.api.ICollateralMover; @@ -66,7 +67,6 @@ private void magnetize(BlockState state, Direction dir, Direction moveDir, int p //TODO: move this into magnet system. although might not be needed as there it only serves since directions must be discrete if (MagnetsModule.affectEntities && blockDist > 1) { - var entities = level.getEntities((Entity) null, new AABB(worldPosition) .expandTowards(new Vec3(dir.step().mul(blockDist))), this::canPullEntity); for (Entity e : entities) { @@ -99,6 +99,8 @@ private void magnetize(BlockState state, Direction dir, Direction moveDir, int p } private void pushEntity(Direction dir, double magnitude, Entity e) { + if(e instanceof Gravisand) magnitude = -magnitude; //idk why its needed + double distanceFromMagnetSq = e.distanceToSqr(worldPosition.getCenter()); double invSquared = 1 / distanceFromMagnetSq; // magic number chosen. around 1 block hover height for iron golems diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/magnetsystem/MagnetSystem.java b/src/main/java/org/violetmoon/quark/addons/oddities/magnetsystem/MagnetSystem.java index 40eb8c38d..e1f703531 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/magnetsystem/MagnetSystem.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/magnetsystem/MagnetSystem.java @@ -100,12 +100,18 @@ public static void applyForce(Level world, BlockPos pos, int magnitude, boolean public static ICollateralMover.MoveResult getPushAction(MagnetBlockEntity magnet, BlockPos pos, BlockState state, Direction moveDir) { if(state.getBlock() instanceof MovingMagnetizedBlock)return ICollateralMover.MoveResult.SKIP; + + Level world = magnet.getLevel(); if(world != null && canBlockBeMagneticallyMoved(state, pos, world, moveDir, magnet)) { BlockPos frontPos = pos.relative(moveDir); BlockState frontState = world.getBlockState(frontPos); if(state.getBlock() instanceof ICollateralMover cm && cm.isCollateralMover(world, magnet.getBlockPos(), moveDir, pos)){ + //now check if block in front is immovable (probably meaning unbreakable) + if(MagnetsModule.usePistonLogic && !PistonBaseBlock.isPushable(frontState, world, frontPos, moveDir, true, moveDir.getOpposite())){ + return ICollateralMover.MoveResult.PREVENT; + } return cm.getCollateralMovement(world, magnet.getBlockPos(), moveDir, moveDir, pos); } @@ -133,6 +139,11 @@ public static boolean isBlockMagnetic(BlockState state) { public static boolean canBlockBeMagneticallyMoved(BlockState state, BlockPos pos, Level level, Direction moveDir, BlockEntity magnet) { Block block = state.getBlock(); + //cant push stuff that pistons cant push + if(MagnetsModule.usePistonLogic && !PistonBaseBlock.isPushable(state, level, pos, moveDir, false, moveDir.getOpposite())){ + return false; + } + if (block == Blocks.PISTON || block == Blocks.STICKY_PISTON) { if (state.getValue(PistonBaseBlock.EXTENDED)) return false; diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/module/MagnetsModule.java b/src/main/java/org/violetmoon/quark/addons/oddities/module/MagnetsModule.java index f87a208b2..f9b3b59ba 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/module/MagnetsModule.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/module/MagnetsModule.java @@ -51,6 +51,9 @@ public class MagnetsModule extends ZetaModule { @Config(flag = "magnet_pre_end") public static boolean usePreEndRecipe = false; + @Config(flag = "use_piston_logic", description = "When true magnets will never push something that pistons cant push. Disable to have further control. This allows iron rods to break obsidian for example") + public static boolean usePistonLogic = true; + @Config(flag = "magnetic_entities", description = "Allows magnets to push and pull entities in the 'affected_by_magnets' tag (edit it with datapack). Turning off can reduce lag") public static boolean affectEntities = true; diff --git a/src/main/java/org/violetmoon/quark/content/experimental/config/VariantsConfig.java b/src/main/java/org/violetmoon/quark/content/experimental/config/VariantsConfig.java index 8a8eef7c8..49db0a896 100644 --- a/src/main/java/org/violetmoon/quark/content/experimental/config/VariantsConfig.java +++ b/src/main/java/org/violetmoon/quark/content/experimental/config/VariantsConfig.java @@ -225,7 +225,7 @@ private Block getSuffixedBlock(Block ogBlock, String suffix) { if(ret != null) return ret; //for ec format. this could have its own config... bad code - ret = getSuffixedBlock(mod, name, suffix, "%s:"+namespace+"\\%s_%s"); + ret = getSuffixedBlock(mod, name, suffix, "%s:"+namespace+"/%s_%s"); if(ret != null) return ret; }