Skip to content

Commit

Permalink
magnets will now also call piston logic to determine moveable stuff. …
Browse files Browse the repository at this point in the history
…Gravisand has inverted movement when pulled by magnets
  • Loading branch information
MehVahdJukaar committed Jul 26, 2024
1 parent 14769bd commit 7bdaf01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7bdaf01

Please sign in to comment.