package ch.deletescape.pathetic.mixin; import ch.deletescape.pathetic.LastSteppedOnStore; import ch.deletescape.pathetic.PatheticProperties; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.state.StateManager; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // TODO: set default step count value to 0 in constructor @Mixin(Block.class) public abstract class BlockMixin { @Inject(at = @At("RETURN"), method = "appendProperties") private void pathetic_appendProperties(StateManager.Builder builder, CallbackInfo ci) { builder.add(PatheticProperties.STEP_COUNT); } // TODO: half of this should probably be done with block entity tick shit @Inject(at = @At("RETURN"), method = "onSteppedOn") private void pathetic_onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo ci) { if (entity.isPlayer()) { Block block = state.getBlock(); long currentTime = world.getTime(); if (block == Blocks.DIRT || block == Blocks.GRASS_BLOCK) { if (currentTime - LastSteppedOnStore.putIfAbsent(pos, currentTime) >= 50) { int currentStepCount = state.get(PatheticProperties.STEP_COUNT); if (currentStepCount < 5) { world.setBlockState(pos, state.with(PatheticProperties.STEP_COUNT, currentStepCount + 1)); } if (currentStepCount >= 5) { Block.replace(state, Blocks.DIRT_PATH.getDefaultState().with(PatheticProperties.IS_AUTOPATH, true), world, pos, Block.NOTIFY_ALL); } } } else if (block == Blocks.DIRT_PATH && state.get(PatheticProperties.IS_AUTOPATH)) { // TODO: turn blocks back into grass blocks if no one steps on them for a specified amount of time, we mostly need to do // block entity hackery for that, and idk if we can do that with mixins tbh } } } }