Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized mana enchanter multiblock checking #4465

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ManaEnchanterBlockEntity extends BotaniaBlockEntity implements Mana
private static final String TAG_ITEM = "item";
private static final String TAG_ENCHANTS = "enchantsToApply";
private static final int CRAFT_EFFECT_EVENT = 0;
private static final int IDLE_CHECK_INTERVAL_TICKS = 10;

private static final String[][] PATTERN = new String[][] {
{
Expand Down Expand Up @@ -136,6 +137,8 @@ public class ManaEnchanterBlockEntity extends BotaniaBlockEntity implements Mana

public int stage3EndTicks = 0;

private int idleTicks = 0;

private int manaRequired = -1;
private int mana = 0;

Expand Down Expand Up @@ -256,26 +259,31 @@ public static void commonTick(Level level, BlockPos worldPosition, BlockState st
for (BlockPos offset : PYLON_LOCATIONS.get(axis)) {
BlockEntity tile = level.getBlockEntity(worldPosition.offset(offset));
if (tile instanceof PylonBlockEntity pylon) {
pylon.activated = self.stage == State.GATHER_MANA;
if (self.stage == State.GATHER_MANA) {
boolean gatheringMana = self.stage == State.GATHER_MANA;
pylon.activated = gatheringMana;
if (gatheringMana) {
pylon.centerPos = worldPosition;
}
}
}

if (self.stage != State.IDLE) {
self.stageTicks++;
} else {
self.idleTicks++;
}

if (level.isClientSide) {
if (level.isClientSide || self.stage == State.IDLE && self.idleTicks % IDLE_CHECK_INTERVAL_TICKS != 0) {
return;
}

if (FORMED_MULTIBLOCK.get().validate(level, worldPosition.below()) == null) {
Rotation rot = getAxisRotation(axis);
if (!FORMED_MULTIBLOCK.get().validate(level, worldPosition.below(), rot)) {
level.setBlockAndUpdate(worldPosition, Blocks.LAPIS_BLOCK.defaultBlockState());
XplatAbstractions.INSTANCE.sendToNear(level, worldPosition, new BotaniaEffectPacket(EffectType.ENCHANTER_DESTROY,
worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5));
level.playSound(null, worldPosition, BotaniaSounds.enchanterFade, SoundSource.BLOCKS, 1F, 1F);
return;
}

switch (self.stage) {
Expand Down Expand Up @@ -465,6 +473,14 @@ public static Direction.Axis canEnchanterExist(Level world, BlockPos pos) {
};
}

private static Rotation getAxisRotation(Direction.Axis axis) {
return switch (axis) {
case X -> Rotation.NONE;
case Z -> Rotation.CLOCKWISE_90;
default -> throw new IllegalStateException("Enchanter should only ever be facing in X or Z direction");
};
}

@Override
public boolean canAttachSpark(ItemStack stack) {
return true;
Expand Down
Loading