Skip to content

Commit

Permalink
Prefix interface method with modid
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Nov 4, 2023
1 parent a9a8051 commit c929956
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package me.jellysquid.mods.lithium.common.block;

public interface BlockStateFlagHolder {
int getAllFlags();
int lithium$getAllFlags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

/**
* This mixin uses the block caching system to be able to skip entity block interactions when the entity is not a player
* and the nearby blocks cannot be interacted with by touching them.
*/
@Mixin(Entity.class)
public abstract class EntityMixin implements BlockCacheProvider {
@Inject(
Expand Down Expand Up @@ -49,7 +53,7 @@ private void assumeNoTouchableBlock(CallbackInfo ci) {
private void checkTouchableBlock(CallbackInfo ci, Box box, BlockPos blockPos, BlockPos blockPos2, BlockPos.Mutable mutable, int i, int j, int k, BlockState blockState) {
BlockCache bc = this.getBlockCache();
if (bc.canSkipBlockTouching() &&
0 != (((BlockStateFlagHolder)blockState).getAllFlags() & 1 << BlockStateFlags.ENTITY_TOUCHABLE.getIndex())
0 != (((BlockStateFlagHolder)blockState).lithium$getAllFlags() & 1 << BlockStateFlags.ENTITY_TOUCHABLE.getIndex())
) {
bc.setCanSkipBlockTouching(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AbstractBlock.AbstractBlockState.class)
public class AbstractBlockStateMixin implements BlockStateFlagHolder {
@Unique
private int flags;

@Inject(method = "initShapeCache", at = @At("RETURN"))
private void init(CallbackInfo ci) {
this.initFlags();
}

@Unique
private void initFlags() {
TrackedBlockStatePredicate.FULLY_INITIALIZED.set(true);

Expand All @@ -35,7 +38,7 @@ private void initFlags() {
}

@Override
public int getAllFlags() {
public int lithium$getAllFlags() {
return this.flags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void initFlagCounters(PalettedContainer<BlockState> palettedContainer, P
}

private static void addToFlagCount(short[] countsByFlag, BlockState state, int change) {
int flags = ((BlockStateFlagHolder) state).getAllFlags();
int flags = ((BlockStateFlagHolder) state).lithium$getAllFlags();
int i;
while ((i = Integer.numberOfTrailingZeros(flags)) < 32 && i < countsByFlag.length) {
//either count up by one (prevFlag not set) or down by one (prevFlag set)
Expand Down Expand Up @@ -106,8 +106,8 @@ private void updateFlagCounters(int x, int y, int z, BlockState newState, boolea
if (countsByFlag == null) {
return;
}
int prevFlags = ((BlockStateFlagHolder) oldState).getAllFlags();
int flags = ((BlockStateFlagHolder) newState).getAllFlags();
int prevFlags = ((BlockStateFlagHolder) oldState).lithium$getAllFlags();
int flags = ((BlockStateFlagHolder) newState).lithium$getAllFlags();

int flagsXOR = prevFlags ^ flags;
//we need to iterate over indices that changed or are in the listeningMask
Expand Down

0 comments on commit c929956

Please sign in to comment.