Skip to content

Commit

Permalink
Silly magnet waxing, spent so long on this lol
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Feb 16, 2024
1 parent d454e4a commit 4183e31
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dependencies.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
forge=47.1.3
zeta=1.0-14.61
zeta=1.0-14.64
jei=4712868
terrablender=1.20.1-3.0.0.169
flan=4819286
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public class MagnetBlock extends ZetaBlock implements EntityBlock {

public static final DirectionProperty FACING = BlockStateProperties.FACING;
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
public static final BooleanProperty WAXED = BooleanProperty.create("waxed");
public boolean waxed = false;

public MagnetBlock(@Nullable ZetaModule module) {
super("magnet", module, Properties.copy(Blocks.IRON_BLOCK));
registerDefaultState(defaultBlockState().setValue(FACING, Direction.DOWN).setValue(POWERED, false));
registerDefaultState(defaultBlockState().setValue(FACING, Direction.DOWN).setValue(POWERED, false).setValue(WAXED, false));

if(module == null) //auto registration below this line
return;
Expand All @@ -53,7 +55,7 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable BlockGetter worl

@Override
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
builder.add(FACING, POWERED);
builder.add(FACING, POWERED, WAXED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;

import org.violetmoon.quark.addons.oddities.block.MagnetBlock;
import org.violetmoon.quark.addons.oddities.magnetsystem.MagnetSystem;
import org.violetmoon.quark.addons.oddities.module.MagnetsModule;
Expand All @@ -25,12 +24,12 @@ public static void tick(Level level, BlockPos pos, BlockState state, MagnetBlock
if(powered) {
Direction dir = state.getValue(MagnetBlock.FACING);
int power = level.getBestNeighborSignal(pos);
be.magnetize(dir, dir, power);
be.magnetize(dir.getOpposite(), dir, power);
be.magnetize(state, dir, dir, power);
be.magnetize(state, dir.getOpposite(), dir, power);
}
}

private void magnetize(Direction dir, Direction moveDir, int power) {
private void magnetize(BlockState state, Direction dir, Direction moveDir, int power) {
if(level == null)
return;

Expand All @@ -51,24 +50,23 @@ private void magnetize(Direction dir, Direction moveDir, int power) {

if(!level.isClientSide && targetState.getBlock() != Blocks.MOVING_PISTON && targetState.getBlock() != MagnetsModule.magnetized_block) {
PushReaction reaction = MagnetSystem.getPushAction(this, targetPos, targetState, moveDir);
if(reaction == PushReaction.IGNORE || reaction == PushReaction.DESTROY) {
if (reaction == PushReaction.IGNORE || reaction == PushReaction.DESTROY) {
BlockPos frontPos = targetPos.relative(moveDir);
BlockState frontState = level.getBlockState(frontPos);
if(frontState.isAir())
if (frontState.isAir())
MagnetSystem.applyForce(level, targetPos, power - i + 1, dir == moveDir, moveDir, i, worldPosition);
}
}

if(!targetState.isAir())
if (!targetState.isAir())
break;

if(level.isClientSide && Math.random() <= particleChance) {
if (!state.getValue(MagnetBlock.WAXED) && level.isClientSide && Math.random() <= particleChance) {
double x = targetPos.getX() + (xOff == 0 ? 0.5 : Math.random());
double y = targetPos.getY() + (yOff == 0 ? 0.5 : Math.random());
double z = targetPos.getZ() + (zOff == 0 ? 0.5 : Math.random());
level.addParticle(ParticleTypes.SNEEZE, x, y, z, xOff, yOff, zOff);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.violetmoon.quark.addons.oddities.module;

import com.google.common.collect.Lists;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;

import org.violetmoon.quark.addons.oddities.block.MagnetBlock;
import org.violetmoon.quark.addons.oddities.block.MovingMagnetizedBlock;
import org.violetmoon.quark.addons.oddities.block.be.MagnetBlockEntity;
Expand All @@ -24,6 +22,7 @@
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.util.Hint;
import org.violetmoon.zeta.util.handler.ToolInteractionHandler;

import java.util.List;

Expand Down Expand Up @@ -54,6 +53,8 @@ public final void register(ZRegister event) {
magnet = new MagnetBlock(this);
magnetized_block = new MovingMagnetizedBlock(this);

ToolInteractionHandler.registerWaxedBlockBooleanProperty(this, magnet, MagnetBlock.WAXED);

magnetType = BlockEntityType.Builder.of(MagnetBlockEntity::new, magnet).build(null);
Quark.ZETA.registry.register(magnetType, "magnet", Registries.BLOCK_ENTITY_TYPE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public InteractionResult useOn(UseOnContext context) {

// For inserting stuff into chests easily
// Check if they are shifting, and it isn't on the client
if (player.isShiftKeyDown() && !context.getLevel().isClientSide()) {
if (player != null && player.isShiftKeyDown() && !context.getLevel().isClientSide()) {
BlockEntity targetedBE = context.getLevel().getBlockEntity(BlockPos.containing(context.getClickLocation()));
if (targetedBE instanceof ChestBlockEntity chest) {
Optional<IItemHandler> optionalItemHandler = chest.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.NORTH).resolve();
Expand Down
2 changes: 1 addition & 1 deletion zupdate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Behold my perfect creation, grabs the latest version of zeta and the zeta entry in dependencies.properties to said version
# Behold my perfect creation, grabs the latest version of zeta and updates the zeta entry in dependencies.properties to said version

# Zeta's XML from Jared's Maven
xml_url="https://maven.blamejared.com/org/violetmoon/zeta/Zeta/maven-metadata.xml"
Expand Down

0 comments on commit 4183e31

Please sign in to comment.