Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jun 27, 2024
2 parents a85491c + e9d5794 commit 139dee6
Show file tree
Hide file tree
Showing 95 changed files with 2,238 additions and 1,191 deletions.
594 changes: 303 additions & 291 deletions build.gradle

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Wed May 15 22:23:11 UTC 2024
#Tue Jun 11 13:41:16 UTC 2024
mapping_version=1.20.1
version=4.0
mod_name=Quark
mc_version=1.20.1
mapping_channel=official
mod_id=quark
build_number=444
build_number=458
dir_output=../Build Output/Quark/
4 changes: 3 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- Fix boat tags being broken
- Fallen logs can rarely spawn on water
- Fallen logs can no longer spawn on ice and other non terrain blocks (added tag for them)
- Fallen log decoration (moss and vines) are now biome temperature and humidify dependent. No more moss in snowy biomes
11 changes: 10 additions & 1 deletion contributors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Rynam90=1
JithuJilladi=2
YoItsSteve=1
Quu1337=2
Tiborius=2
Tiborius7=2
Marvl102=1
SpencerAU=1
GiraffeSummer=2
Expand Down Expand Up @@ -948,3 +948,12 @@ DarthTrayus05=2
Rpzghost=1
MontyDergon=2
trueherosaitama=2
KronBlom84=2
Phqntum=1
Korii23=1
Kelpiesaurus=1
HyouSol=2
LightroCN=2
Grawlix=1
Milinen=2
ArzinistMC=2
4 changes: 2 additions & 2 deletions dependencies.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
forge=47.1.3
zeta=1.0-15.72
zeta=1.0-19
jei=4712868
terrablender=1.20.1-3.0.0.169
flan=4819286
flan=5290172
lootr=4608503
emi=1.0.24+1.20.1
spark=4738952
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,39 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.PushReaction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.quark.addons.oddities.block.be.MagnetBlockEntity;
import org.violetmoon.quark.addons.oddities.block.be.MagnetizedBlockBlockEntity;
import org.violetmoon.quark.addons.oddities.magnetsystem.MagnetSystem;
import org.violetmoon.quark.addons.oddities.module.MagnetsModule;
import org.violetmoon.zeta.api.ICollateralMover;
import org.violetmoon.zeta.block.ZetaBlock;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.registry.RenderLayerRegistry;

import java.util.List;

public class MagnetBlock extends ZetaBlock implements EntityBlock {
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));
super("magnet", module, Properties.copy(Blocks.IRON_BLOCK)
.hasPostProcess(MagnetBlock::isPowered)
.lightLevel(state -> state.getValue(POWERED) ? 3 : 0));

registerDefaultState(defaultBlockState().setValue(FACING, Direction.DOWN).setValue(POWERED, false).setValue(WAXED, false));


if(module == null) //auto registration below this line
return;
setCreativeTab(CreativeModeTabs.REDSTONE_BLOCKS);

module.zeta.renderLayerRegistry.put(this, RenderLayerRegistry.Layer.CUTOUT);

}

@Override
Expand All @@ -63,7 +70,7 @@ public void neighborChanged(@NotNull BlockState state, @NotNull Level worldIn, @
super.neighborChanged(state, worldIn, pos, blockIn, fromPos, isMoving);

boolean wasPowered = state.getValue(POWERED);
boolean isPowered = isPowered(worldIn, pos, state.getValue(FACING));
boolean isPowered = hasPower(worldIn, pos, state.getValue(FACING));
if(isPowered != wasPowered)
worldIn.setBlockAndUpdate(pos, state.setValue(POWERED, isPowered));
}
Expand All @@ -81,43 +88,47 @@ public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int act
return false;

BlockPos endPos = targetPos.relative(moveDir);
PushReaction reaction = MagnetSystem.getPushAction(be, targetPos, targetState, moveDir);
if(reaction != PushReaction.IGNORE && reaction != PushReaction.DESTROY)
var reaction = MagnetSystem.getPushAction(be, targetPos, targetState, moveDir);
if(reaction != ICollateralMover.MoveResult.MOVE && reaction != ICollateralMover.MoveResult.BREAK)
return false;

BlockEntity tilePresent = world.getBlockEntity(targetPos);
CompoundTag tileData = new CompoundTag();
if(tilePresent != null && !(tilePresent instanceof MagnetizedBlockBlockEntity))
if(tilePresent != null && !(tilePresent instanceof MagnetizedBlockBlockEntity)) {
tileData = tilePresent.saveWithFullMetadata();
tilePresent.setRemoved();
}

BlockState setState = MagnetsModule.magnetized_block.defaultBlockState().setValue(MovingMagnetizedBlock.FACING, moveDir);
MagnetizedBlockBlockEntity movingTile = new MagnetizedBlockBlockEntity(endPos, setState, targetState, tileData, moveDir);

if(!world.isClientSide && reaction == PushReaction.DESTROY) {
BlockState blockstate = world.getBlockState(endPos);
Block.dropResources(blockstate, world, endPos, tilePresent);
if(!world.isClientSide && reaction == ICollateralMover.MoveResult.BREAK) {
world.destroyBlock(endPos, true);
}

if(tilePresent != null)
tilePresent.setRemoved();

world.setBlock(endPos, setState, 68);
world.setBlockEntity(movingTile);

world.setBlock(targetPos, Blocks.AIR.defaultBlockState(), 67);

//TODO:push iron golems here...

return true;
}

private boolean isPowered(Level worldIn, BlockPos pos, Direction facing) {
private static boolean isPowered(BlockState state, BlockGetter pLevel, BlockPos pPos) {
return state.getValue(POWERED);
}

private boolean hasPower(Level worldIn, BlockPos pos, Direction facing) {
return worldIn.hasNeighborSignal(pos);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction facing = context.getNearestLookingDirection().getOpposite();
return defaultBlockState().setValue(FACING, facing)
.setValue(POWERED, isPowered(context.getLevel(), context.getClickedPos(), facing));
.setValue(POWERED, hasPower(context.getLevel(), context.getClickedPos(), facing));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,160 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.violetmoon.quark.addons.oddities.block.MagnetBlock;
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.experimental.module.VariantSelectorModule;
import org.violetmoon.quark.mixin.mixins.accessor.AccessorServerGamePacketListener;
import org.violetmoon.zeta.api.ICollateralMover;

public class MagnetBlockEntity extends BlockEntity {

public MagnetBlockEntity(BlockPos pos, BlockState state) {
super(MagnetsModule.magnetType, pos, state);
}

public static void tick(Level level, BlockPos pos, BlockState state, MagnetBlockEntity be) {
boolean powered = state.getValue(MagnetBlock.POWERED);

if(powered) {
Direction dir = state.getValue(MagnetBlock.FACING);
int power = level.getBestNeighborSignal(pos);
be.magnetize(state, dir, dir, power);
be.magnetize(state, dir.getOpposite(), dir, power);
}
}

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

double magnitude = (dir == moveDir ? 1 : -1);

double particleMotion = 0.05 * magnitude;
double particleChance = 0.2;
double xOff = dir.getStepX() * particleMotion;
double yOff = dir.getStepY() * particleMotion;
double zOff = dir.getStepZ() * particleMotion;

for(int i = 1; i <= power; i++) {
BlockPos targetPos = worldPosition.relative(dir, i);
BlockState targetState = level.getBlockState(targetPos);

if(targetState.getBlock() == MagnetsModule.magnetized_block)
break;

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) {
BlockPos frontPos = targetPos.relative(moveDir);
BlockState frontState = level.getBlockState(frontPos);
if (frontState.isAir())
MagnetSystem.applyForce(level, targetPos, power - i + 1, dir == moveDir, moveDir, i, worldPosition);
}
}

if (!targetState.isAir())
break;

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);
}
}
}
public MagnetBlockEntity(BlockPos pos, BlockState state) {
super(MagnetsModule.magnetType, pos, state);
}

public static void tick(Level level, BlockPos pos, BlockState state, MagnetBlockEntity be) {
boolean powered = state.getValue(MagnetBlock.POWERED);

if (powered) {
Direction dir = state.getValue(MagnetBlock.FACING);
int power = level.getBestNeighborSignal(pos);
be.magnetize(state, dir, dir, power);
be.magnetize(state, dir.getOpposite(), dir, power);
}
}

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

double magnitude = (dir == moveDir ? 1 : -1);

int blockDist = 1;
for (; blockDist <= power; blockDist++) {
BlockPos targetPos = worldPosition.relative(dir, blockDist);
BlockState targetState = level.getBlockState(targetPos);


if (!level.isClientSide) {
var reaction = MagnetSystem.getPushAction(this, targetPos, targetState, moveDir);
if (reaction == ICollateralMover.MoveResult.MOVE || reaction == ICollateralMover.MoveResult.BREAK) {
MagnetSystem.applyForce(level, targetPos, power - blockDist + 1, dir == moveDir, moveDir, blockDist, worldPosition);
} else if (reaction == ICollateralMover.MoveResult.PREVENT) break;
}

if (targetState.getBlock() == MagnetsModule.magnetized_block && level.getBlockEntity(targetPos) instanceof MagnetizedBlockBlockEntity mbe) {
targetState = mbe.blockState;
}

if (!canFluxPenetrate(targetPos, targetState)) break;
}

//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) {
pushEntity(dir, magnitude, e);
}
}

//particles
if (level.isClientSide && !state.getValue(MagnetBlock.WAXED)){

double particleMotion = 0.06 * magnitude;
double particleChance = 0.2;
double xOff = dir.getStepX() * particleMotion;
double yOff = dir.getStepY() * particleMotion;
double zOff = dir.getStepZ() * particleMotion;

double particleOffset = moveDir.getAxisDirection() == Direction.AxisDirection.POSITIVE ? 1 : -1;

for (int j = 1; j < blockDist; j++) {
if (level.random.nextFloat() <= particleChance) {
BlockPos targetPos = worldPosition.relative(dir, j);
double x = targetPos.getX() + getParticlePos(xOff, level.random, particleOffset);
double y = targetPos.getY() + getParticlePos(yOff, level.random, particleOffset);
double z = targetPos.getZ() + getParticlePos(zOff, level.random, particleOffset);
var p = dir == moveDir ? MagnetsModule.repulsorParticle : MagnetsModule.attractorParticle;
level.addParticle(p, x, y, z, xOff, yOff, zOff);
}
}
}
}

private void pushEntity(Direction dir, double magnitude, Entity e) {
double distanceFromMagnetSq = e.distanceToSqr(worldPosition.getCenter());
double invSquared = 1 / distanceFromMagnetSq;
// magic number chosen. around 1 block hover height for iron golems
Vec3 vec = new Vec3(dir.step().mul((float) (invSquared * magnitude * MagnetsModule.entitiesPullForce)));
if (e instanceof IMagneticEntity me) {
me.moveByMagnet(e, vec, this);
} else {
e.push(vec.x(), vec.y(), vec.z());
if (e instanceof ServerPlayer player) {
//reset flying kick time
((AccessorServerGamePacketListener) player.connection).setAboveGroundTickCount(0);
} else {
//hurt mark everybody but the player. its handled by client side code
e.hurtMarked = true;
}
if (e instanceof FallingBlockEntity fb) {
fb.time--;
//hack.
}
e.fallDistance = 0;
}
}

private boolean canPullEntity(Entity e) {
if (this.level.isClientSide) {
if (MagnetsModule.affectsArmor && e instanceof Player) {
for (var armor : e.getArmorSlots()) {
if (MagnetSystem.isItemMagnetic(armor.getItem())) return true;
}
}
return false;
}
if (e instanceof IMagneticEntity) return true;

if (e instanceof ItemEntity ie) {
return MagnetSystem.isItemMagnetic(ie.getItem().getItem());
}

if (e.getType().is(MagnetsModule.magneticEntities)) return true;

if (e instanceof FallingBlockEntity fb) {
return MagnetSystem.isBlockMagnetic(fb.getBlockState());
}

if (MagnetsModule.affectsArmor) {
for (var armor : e.getArmorSlots()) {
if (MagnetSystem.isItemMagnetic(armor.getItem())) return true;
}
}
return false;
}

private boolean canFluxPenetrate(BlockPos targetPos, BlockState targetState) {
return (targetState.isAir()) || targetState.getCollisionShape(level, targetPos).isEmpty();
}

private double getParticlePos(double offset, RandomSource ran, double magnitude) {
return (offset == 0 ? 0.5f + (ran.nextFloat() + ran.nextFloat() - 1) / 2f : (0.5f + magnitude * (ran.nextFloat() - 1.25)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void makeOutput() {
EnchantedBookItem.addEnchantment(out, new EnchantmentInstance(e.getKey(), e.getValue()));
else {
EnchantmentHelper.setEnchantments(enchantments, out);
ItemNBTHelper.getNBT(out).remove(TAG_STACK_MATRIX);
out.removeTagKey(TAG_STACK_MATRIX);
}

setItem(2, out);
Expand Down
Loading

0 comments on commit 139dee6

Please sign in to comment.