Skip to content

Commit

Permalink
Fix projectiles from lecterns
Browse files Browse the repository at this point in the history
  • Loading branch information
ssblur committed Aug 12, 2024
1 parent 8abe79d commit 6578247
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.ssblur.scriptor.item.casters.CasterCrystal;
import com.ssblur.scriptor.word.Spell;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
Expand All @@ -26,7 +25,6 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

public class CastingLecternBlockEntity extends BlockEntity {
public static final int SPELLBOOK_SLOT = 0;
Expand Down Expand Up @@ -108,13 +106,11 @@ public void tick() {
var state = level.getBlockState(getBlockPos());
var direction = state.getValue(CastingLecternBlock.FACING).getOpposite();
var blockPos = this.getBlockPos();
float offsetX = direction.getAxis() == Direction.Axis.X ? Math.signum(blockPos.getX()) : 0.5f;
float offsetZ = direction.getAxis() == Direction.Axis.Z ? Math.signum(blockPos.getZ()) : 0.5f;
var pos = new Vector3f(blockPos.getX() + offsetX, blockPos.getY() + 0.49f, blockPos.getZ() + offsetZ);
var pos = blockPos.getCenter();
var target = new LecternTargetable(this.getLevel(), pos).setFacing(direction);
if(getFocus().getItem() instanceof CasterCrystal crystal) {
var foci = crystal.getTargetables(getFocus(), level);
if(foci.size() > 0) {
if(!foci.isEmpty()) {
focusTarget++;
focusTarget %= foci.size();
var focus = foci.get(focusTarget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public void tick() {
var level = level();
if (level.isClientSide) return;

setDeltaMovement(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z);
setPos(position().add(getDeltaMovement()));

if(this.origin != null)
if (this.position().distanceTo(this.origin) <= 1) return;

// int c = CustomColors.getColor(getColor(), level.getGameTime());
// int r, g, b;
// r = (c & 0xff0000) >> 16;
Expand Down Expand Up @@ -141,8 +147,5 @@ else if (
new Targetable(this.level(), blockHitResult.getBlockPos().offset(blockHitResult.getDirection().getNormal()))
.setFacing(blockHitResult.getDirection())
));

setDeltaMovement(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z);
setPos(position().add(getDeltaMovement()));
}
}

0 comments on commit 6578247

Please sign in to comment.